I'm currently trying to create an Exception handler built into my Windows service, which in an unhandled exception sends a message to another program. I built a method and received a message, but it seems that every time my program throws an error, (I have a call call in the code to force it.) Windows catches it, and the handler is not called. Can someone explain what I'm doing wrong?
Simplified code to explain:
procedure unhandled(); begin raise Exception.Create('Unhandled'); end; procedure ExceptionHandler(ExceptObject: TObject; ExceptAddr: Pointer); begin WriteLn('Display: ' + Exception(ExceptObject).Message); //send Message Here end;
I call this code to run it:
WriteLn('Starting'); ExceptProc := @ExceptionHandler; unhandled();
I expect the output to be as follows:
Launch
Display: Raw
but all he does is display:
Launch
Then the windows return the command line after about 5 seconds.
Why is the handler called incorrectly?
PS I tested these tests in a console application for testing.
EDIT:
Here is some more info:
Apparently, when you have ExceptProc assigned, your program should not throw a common 211 runtime error. I assume this is what Windows catches. From what I see, my program throws this runtime error, and I cannot get ErrorProc to catch it.
source share