views:

315

answers:

3

hi

is there any way to turn off exception message showing during run-time in Delphi application? i think there must be a directive to turn off exception message but i cant remember it.

+2  A: 

I use the IDE to turn it off:

In Delphi 2007, click Tools / Options and go right down to Debugger Options / CodeGear debuggers / Native OS Exceptions. Select "Run Unhandled". The debugger will not halt on exceptions, but act the same as running from an exe. Exceptions will be handled as such.

For directives, I don't know of one that can exactly do the above, but maybe this will help:

http://www.delphibasics.co.uk/ByType.asp?Type=Compiler%20Directive

Hein du Plessis
+1  A: 

Are you running OpenGL by any chance? I've not tried it with the more recent Codegear/OpenGL builds, but there used to be an issue that OpenGL didn't disable FPU exceptions but the IDE expected these to be turned off by default (as Microsoft libraries do) so the IDE would report FPU exceptions ad-nauseam despite these being of no consequence.

The solution was to explicitly turn of FPU exceptions, which you can do in code using the statement.

Set8087CW($133F);

There may be other libraries where this causes an issue too.

Cruachan
+10  A: 

Most exception messages can be suppressed by handling the TApplication.OnException event. The application object only displays an exception message if there isn't a handler assigned to that event. You're welcome to call TApplication.ShowException in your handler for certain exceptions if you want.

That event is fired for exceptions that occur while running in the VCL message loop. Exceptions that occur elsewhere terminate either your program or the current thread. Also, the event is fired only for exceptions that descend from Exception; exceptions that descend from other classes are passed directly to SysUtils.ShowException.

Whether you display a message or not, your program is still in an indeterminate state once an exception has occurred that you haven't handled. Merely suppressing the message is akin to sweeping the dust under the rug. A better course of action is to use an exception-logging tool like MadExcept, EurekaLog, or JclDebug that records information about the exception and gives your customers the option of sending the reports back to you so you can reproduce the conditions of the error and fix it.

Rob Kennedy
Perfect answer, deserves +2.
Chris Thornton
EurekaLog (and maybe the others?) can also perform an auto re-start of the app. If the goal is to keep the users from seeing the errors, AND you want to have high availability (kiosk maybe?) then use one of these debug logger apps to record the error, and silently re-start the app. Otherwise, you're going to be hiding errors until your app degrades to the point where it can't run and a reboot is rquired anyway.
Chris Thornton