kyl011199
asked on
Global exception handler,
I am trying to write a program that does not use forms Unit So the application object also does not exist.
I am using bare API functions RegisterWindowsClass, CreateWindowsEx and my own message loop. I am also using some units that are written by others.
My Question is, how to cacth and handle exceptions that may be thrown anywhere(from my own units or from the others' units) So how can I write a global exception handler like Application.OnException handler.
Thanx,
I am using bare API functions RegisterWindowsClass, CreateWindowsEx and my own message loop. I am also using some units that are written by others.
My Question is, how to cacth and handle exceptions that may be thrown anywhere(from my own units or from the others' units) So how can I write a global exception handler like Application.OnException handler.
Thanx,
Use this one:
procedure ExceptHandler(ExceptObject : TObject; ExceptAddr: Pointer);
begin
// here you have the exception...
end;
procedure InitExceptions;
begin
ExceptProc := @ExceptHandler;
end;
Regards, Madshi.
procedure ExceptHandler(ExceptObject
begin
// here you have the exception...
end;
procedure InitExceptions;
begin
ExceptProc := @ExceptHandler;
end;
Regards, Madshi.
Listening
ASKER
Both of you are right.
Madshi: I tried the exceptProc with the following code.
Procedure ExceptHandler(...);
Begin
ShowMessage('error');
end;
procedure RaiseException;
Begin
Raise Exception.Create('TEST');
End;
....
Begin
exceptProc:= @exceptHandler;
RaiseException;
End;
the thrown exception was caught by ExceptHandler but after exceptHandler returned Delphi displayed another error message (as if it called ShowException procedure)
RunTime Error at XXXX address..
How can I get rid of this message..
Thanx you both,
Hmmm... The reason is that Delphi doesn't expect that your program continues running after such an exception occured. If you want to catch the exception and continue with your program you have to use Raymond's suggestion. Otherwise you should call "Halt" or "ExitProcess" in the last line of your ExcptHandler procedure. (Look at the source of SysUtils.ExceptHandler, there they call "Halt" in the last line).
Regards, Madshi.
Regards, Madshi.
ASKER
Madshi send your comment as answer
Lischke I will submit a dummy question for your getting the points.
Thnx you both..
Lischke I will submit a dummy question for your getting the points.
Thnx you both..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if PeekMessage(...) then
begin
:
try
DispatchMessage(Msg);
except
on EZeroDivide do HandleZeroDivide;
etc.
end;
end;
Ciao, Mike