Catch the time when madExcept finishes the file

delphi package - automated exception handling
Post Reply
starhu
Posts: 1
Joined: Sun Apr 07, 2019 8:37 pm

Catch the time when madExcept finishes the file

Post by starhu »

I would like to save the log to database. The problem is that I cannot catch when madExcept finishes the file.

I use this code
procedure TMainForm.MadExceptionHandlerException(const exceptIntf: IMEException;
var handled: Boolean);
Begin

try
exceptIntf.BugReportFile :=ExtractFilePath(ParamStr(0)) + 'MyExport\H\' + 'H.txt';
exceptIntf.ScreenShot.SavePng(ExtractFilePath(ParamStr(0)) + 'MyExport\H\' + 'H-.png');
Finally
MyProcedureSaveFilesToDatabase; // <- when I run this the file is still being created, so ExtractFilePath(ParamStr(0)) + 'MyExport\H\' + 'H.txt'; doesn't exists yet
End;

Any ideas? Thank you.
iconic
Site Admin
Posts: 1065
Joined: Wed Jun 08, 2005 5:08 am

Re: Catch the time when madExcept finishes the file

Post by iconic »

Hello,

BugReportFile may not exist yet to work with inside your finally routine however exceptIntf.BugReport should already be filled at that moment and the string contents are the exact contents that are saved to BugReportFile. You could use the string contents directly instead. I imagine you're probably just opening the file anyhow once on disk? You wouldn't have to by using the string directly

--Iconic
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Catch the time when madExcept finishes the file

Post by madshi »

starhu wrote:The problem is that I cannot catch when madExcept finishes the file.
You can use RegisterExceptionHandler with the epCompleteReport parameter. However, if the user presses "close application" before the bug report is complete, you won't get notified at all.
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Catch the time when madExcept finishes the file

Post by madshi »

P.S: I'm not sure from the top of my head about the exact order in which madExcept does everything. It's possible even epCompleteReport handlers are called before the bug report file is actually written to disk. So as iconic suggested, it might make sense to not rely on madExcept's writing of the bug report file, but to instead grab the bug report directly from "excepIntf" by calling "exceptIntf.BugReport". However, if you do this from a "normal" exception handler (instead of epCompleteReport), you force madExcept to block and wait for the creation of the bug report to complete. Which is otherwise done in a background thread.

Practically, if you call exceptIntf.BugReport e.g. within a epQuickFiltering handler, you delay the creation of the exception box, because madExcept is forced to first complete the creation of the full bug report, because your handler returns. By default, madExcept first shows the exception box, with only partial information, and then updates it when the bug report is complete. This approach has the big advantage that the exception box can be shown almost immediately.
Post Reply