Is it possible to construct a snippet of code in Delphi that would make a hypothetical EChuckNorrisException uncatchable?
For the Java programming language I just found this has been answered with Yes in Uncatchable ChuckNorrisException
Is it possible to construct a snippet of code in Delphi that would make a hypothetical EChuckNorrisException uncatchable?
For the Java programming language I just found this has been answered with Yes in Uncatchable ChuckNorrisException
No. In Delphi, it's possible to raise any object (TObject descendant,) though by convention this is usually limited to objects that descend from the base Exception class. And it's possible to create a blanket exception handler that will catch anything.
Most catchall exception handlers that try to report information in some way look like this:
try ... except on E: Exception do ... end; So if you raise something that does not descend from Exception, it will go through this style without getting caught.
However, it's also possible to write it like this:
try ... except ... end; Nothing will get by that style of exception handler.
If you raise an exception that is not caught anywhere, the program will immediately terminate with an error. If that's the intended effect, it's possible to do the same thing by calling Halt with a nonzero error code.
Exception or not, ultimately go through an OS API call to actually raise the exception, such as RaiseException() on Windows. The RTL has core exception handlers in place to catch just about any type of exception the OS can report. Raised objects are wrapped with a special exception code so those handlers can recognize them and decode the raw exception data back into the original objects when triggering except blocks.halt to the trick?Sometimes exceptions raised within a dll and not caught within that dll are not caught by the exception handler of the calling application either. I wonder whether it is possible to mimic that behavior without using a dll?
"You can't throw a ChuckNorrisException, it throws you :)"