Delphi .NET (2) Database (71) Delphi IDE (89) Network (39) Printing (3) Strings (12) VCL (83) Windows with Delphi (280)
Exchange Links About this site Links to us 
|
A global exception handler
2 comments. Current rating: (2 votes). Leave comments and/ or rate it.
You may want your own global exception handler to handle "common" errors such as "out of space," etc.
If you try to create a global exception handler, you will experience that
surrounding the 'Application.Run' command in the .dpr with a try...except block fails.
You will redirect TApplication's "OnException" event to your main form's exception handler "MyExceptionHandler". The redirection is done in FormCreate, similar to assigning Application.OnHint:
 | |  | | TForm = class()..
procedure MyExceptionHandler(Sender : TObject; E : Exception);
end;
procedure TForm1.MyExceptionHandler(
Sender : TObject; E : Exception );
var
wRetVal : Word;
begin
wRetVal := MessageDlg('ERROR: ' + E.message,
mtError, mbAbortRetryIgnore, 0);
case wRetVal of
mrAbort:;
mrRetry:;
mrIgnore:;
end;
{ or call the default exception handler:
Application.ShowException(E); }
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnException := MyExceptionHandler;
end; | |  | |  | You don't like the formatting? Check out SourceCoder then!
Comments:
|
|
|
|
This is very use ful topic for handling exception globally by simply adding pne procrdure.
its good programming practice.
|
|
|
|
|
This is very use ful topic for handling exception globally by simply adding pne procrdure.
its good programming practice.
|
|