views:

254

answers:

5

It used to be that if an exception got raised and propagated far enough up the call stack, Application's main loop would handle it and give you a dialog box. That behavior seems to be broken under Windows Vista. If any exception reaches that level, Vista steps in and says the program "has stopped working," when it used to be perfectly able to continue under XP. (That's the entire reason the exception handler in the main loop is there, for heaven's sake!)

Is there any way to fix this? Preferably in my code itself and not just on my computer, so it won't screw up on other systems?

A: 

catch the exception before it bubbles up to the main UI loop. Just do a high-level catch-all exceptions block:

begin
   Try
     ...
   Except
     ...
   end;
end;

Ultimately, you should not blame Vista for this, nor Delphi. You really should do this, by default, in all your programs.

Randolpho
The one in TApplication *is* the high-level catch-all block. In an event-driven GUI app, it's the last function you can always be sure is running.
Mason Wheeler
+1  A: 

You should add an application level exception handler, http://www.chami.com/tips/delphi/011497D.html. Also you should look into running madexcept to determine why these exceptions are happening, so they can be fixed.

LanceSc
+1 for MadExcept. Amazing product, absolutely amazing.
Tim Sullivan
A: 

Exceptions do behave differently in Vista, along with a lot of other things...

eschneider
+11  A: 

Check to ensure that the global variable in System, JITEnable is still set to 0. If that variable is set to 1, hardware (and external) exceptions will cause that behavior by calling UnhandledExceptionFilter. If it is set to 2, any exception will cause it.

Allen Bauer
Thanks! That worked.
Mason Wheeler
@Mason: How did JITEnable get set in the first place? I thought it defaulted to 0.
Jim McKeeth
A: 

Unfortunately, not all exceptions were nicely caught, even in XP. Ever had an application just vanish, ot just hanging and needing a pskill? (some Delphi version anyone?)
I would try to plug EurekaLog in your app and see if it gives some information on what happens.

François