Reputation: 11768
I have an application which runs multiple threads. I use MadExcept to catch errors and debug it.
The problem is that sometimes after 2-3 hours of running, Windows shows a close program dialog. Why isn't that error handled by MadExcept ?
Upvotes: 1
Views: 1216
Reputation: 6747
Threads are a special case. If you have an exception in a thread, it will not get handled by the global handler, and will usually kill your application. The solution is easy though, with madExcept. Just catch the exception, and tell MadExcept about it. It will log in the usual way, and you won't kill your thread.
uses
{$IFDEF MadExcept}
madExcept,
{$ENDIF}
procedure TMyThread.Execute;
begin
try
SetName;
// do your stuff
except
on errInfo : Exception do
begin
{$IFDEF MadExcept}
HandleException(etNormal, errInfo);
{$ENDIF}
end;
end;
end;
What I also do is have the thread set a "RunningOK" property to true when it starts, and the exception sets it to False. This way my control code can see that something went wrong, and handle that appropriately (either restart it, or report the error, etc)
Upvotes: 1