Page 1 of 1

Catch the time when madExcept finishes the file

Posted: Sun Apr 07, 2019 8:41 pm
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.

Re: Catch the time when madExcept finishes the file

Posted: Mon Apr 08, 2019 6:28 am
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

Re: Catch the time when madExcept finishes the file

Posted: Mon Apr 08, 2019 9:59 am
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.

Re: Catch the time when madExcept finishes the file

Posted: Mon Apr 08, 2019 10:03 am
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.