RAD Studio
ContentsIndex
PreviousUpNext
Default Exception Handling in VCL

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;

 

try
{
  // special statements
}
catch (Exception &E)
{
  Application->HandleException(this);
}

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

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!