4

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

8
  • 2
    The Yes answer there has been deleted after someone posted a comment showing that it was factually incorrect. Commented Dec 14, 2012 at 17:39
  • 1
    I'm sure you have your reasons, but it just seems fishy to me to want to make an uncatchable exception. Commented Dec 14, 2012 at 17:57
  • 4
    +1 for Chuck Norris! ((: Commented Dec 14, 2012 at 18:58
  • 2
    OK, and I guess there is some connection to the actor with the same name? Maybe I'd got it straight away if I'd been from the states... Commented Dec 14, 2012 at 20:15
  • 3
    @AndreasRejbrand see the linked question comments for a hint: "You can't throw a ChuckNorrisException, it throws you :)" Commented Dec 15, 2012 at 8:37

2 Answers 2

9

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.

Sign up to request clarification or add additional context in comments.

2 Comments

To add to this, exceptions in Delphi, whether derived from 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.
Hmmm. Hypothetically: What would happen to that uncatchable Exception? Where would it land? Who can take care of it? If it is the OS you want to reach, wouldn't a simple halt to the trick?
0

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?

2 Comments

The only way to mimic something like that is to use a dll.
That's an uncaught exception because of missing exception handling, not an exception that is uncatchable. You can mimic that behavior by disabling exception handling altogether in an application, see JITEnable in help.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.