Default Exception Handling in VCL

From RAD Studio
Jump to: navigation, search

Go Up to Handling Exceptions in VCL Applications


If your application code does not catch and handle the exceptions that are raised, the exceptions are ultimately caught and handled by the HandleException method of the global Application object. For all exceptions but EAbort, HandleException calls the OnException event handler, if one exists. If there is no OnException event handler (and the exception is not EAbort), HandleException displays a message box with the error message associated with the exception.

There are certain circumstances where HandleException does not get called. Exceptions that occur before or after the execution of the application's Run method are not caught and handled by HandleException. When you write a callback function or a library (.dll or shared object) with functions that can be called by an external application, exceptions can escape the Application object. To prevent exceptions from escaping in this manner, you can insert your own call to the HandleException method:

 try
 { special statements }
 except
   on Exception do
   begin
     Application.HandleException(Self);{ call HandleException }
   end;
 end;

Warning: Do not call HandleException from a thread's exception handling code.

See Also