Programming C# C++ (7) Delphi (619) .NET (2) Database (72) Delphi IDE (90) Network (39) Printing (3) Strings (12) VCL (83) Windows with Delphi (280) Java (8) JavaScript (27) perl (9) php (4) VBScript (1) Visual Basic (1)
Exchange Links About this site Links to us 
|
Creating a 'global' exception handler
This article has not been rated yet. After reading, feel free to leave comments and rate it.
Question:
Is it possible to write a 'global' exception handler where all exception will go to if there is no local exception handler? And if so, how can I get the line number and program unit name where the exception happened?
Answer:
Creating a global exception handler is no problem as the code fragment in the example below shows.
It is to my knowledge not possible to retrieve the line number and/or unit name in which the exception occured.
 | |  | |
type
TForm1 = class(TForm)
procedure MyHandler(Sender: TObject; E : Exception);
procedure FormCreate(Sender: TObject);
end;
procedure TForm1.MyHandler(Sender: TObject; E : Exception);
begin
toLogfile('Exception: ' + E.message);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnException := MyHandler;
end; | |  | |  | You don't like the formatting? Check out SourceCoder then!
Comments:
|