Hello,
I have database code in a thread that is wrapped in a try...except block. With madExcept disabled, the try...except code works as it is supposed to. With madExcept enabled, the madExcept dialog appears and the except code never executes.
The code basically is an insert into a database:
try
Synchronize(InsertData);
except
// code to check database for errors...
end;
procedure InsertData;
begin
Query.ExecSQL;
end;
What can I do to get around this issue?
Regards,
Dan
Try...except problem
The problem is that when there's an exception in the synchronized method, the exception occurred in the context of the main thread, while the try..except statement is in the context of the secondary thread. If you now check out the callstack of the secondary thread, it doesn't help at all, because the crash occurred in the main thread.
Because of this problem madExcept hooks into TThread.Synchronize and catches exceptions in that thread where they are raised (= in the main thread). This is the only way to make sure that you get a proper helpful report with useful stack traces.
How can you work around the problem now? Can't you move the try..except statement into the "InsertData" method? Then everything will work fine again.
Basically madExcept has its own "try..except" block around synchronized method calls.
Because of this problem madExcept hooks into TThread.Synchronize and catches exceptions in that thread where they are raised (= in the main thread). This is the only way to make sure that you get a proper helpful report with useful stack traces.
How can you work around the problem now? Can't you move the try..except statement into the "InsertData" method? Then everything will work fine again.
Basically madExcept has its own "try..except" block around synchronized method calls.