How do I show my custom message for freezing?
How do I show my custom message for freezing?
Using the "detect frozen main thread" option I cannot detect the action event
TMainForm.MadExceptionHandler1Exception(Const exceptIntf: IMEException; Var Handled: Boolean);
and showing my personalized message only shows the madexcept dialog
TMainForm.MadExceptionHandler1Exception(Const exceptIntf: IMEException; Var Handled: Boolean);
and showing my personalized message only shows the madexcept dialog
Re: How do I show my custom message for freezing?
How did you register the exception handler? Did you use the madExcept VCL component, or did you call RegisterExceptionHandler via code?
Re: How do I show my custom message for freezing?
I used the VCL component
Re: How do I show my custom message for freezing?
The key problem here is that the VCL component always tries to call your exception handler in the context of the main thread, but in this specific situation, the main thread is frozen.
My recommendation would be to drop the VCL component, and instead in your code call madExcept.RegisterExceptionHandler():
http://help.madshi.net/madExceptUnit.ht ... ionHandler
This is basically the exact same thing that the VCL component does. However, if you call this API from your own code, you have more control over what it does exactly.
To be more specific, you want to use either the "stDontSync" or "stTrySyncCallAlways" option. However, if you do that, you need to be prepared for that your exception callback function may be called in the context of a secondary thread. As a result, you need to be more careful what you do. E.g. you can't use VCL in a secondary thread because the VCL is not thread safe.
My recommendation would be to drop the VCL component, and instead in your code call madExcept.RegisterExceptionHandler():
http://help.madshi.net/madExceptUnit.ht ... ionHandler
This is basically the exact same thing that the VCL component does. However, if you call this API from your own code, you have more control over what it does exactly.
To be more specific, you want to use either the "stDontSync" or "stTrySyncCallAlways" option. However, if you do that, you need to be prepared for that your exception callback function may be called in the context of a secondary thread. As a result, you need to be more careful what you do. E.g. you can't use VCL in a secondary thread because the VCL is not thread safe.
Re: How do I show my custom message for freezing?
Attached is a project.
I can't catch the error when using handled := True;
using
P_LogException(Exception(exceptIntf.ExceptObject));
If I leave Handled = false it will show the MadExcept dialog then it is possible to capture the error
I can't catch the error when using handled := True;
using
P_LogException(Exception(exceptIntf.ExceptObject));
If I leave Handled = false it will show the MadExcept dialog then it is possible to capture the error
Procedure P_LogException(E: Exception; GerarLog: Boolean = True; MsgAux: String = '');
Var BugTxt: String;
Begin
With NewException(etHidden, E, Nil, True, 0, 0, 0, 0) Do Begin
ListThreads := False;
ShowCpuRegisters := False;
ShowStackDump := False;
ShowDisAsm := False;
ShowRelativeAddrs := True;
ShowRelativeLines := True;
AutoSave := True;
ShowPleaseWaitBox := False;
PluginEnabled['processes'] := False;
PluginEnabled['hardware'] := False;
PluginEnabled['modules'] := False;
BugReportHeader['Data do Erro'] := Datetimetostr(Now);
BugReportHeader['operating system'] := EmptyStr;
BugReportHeader['system language'] := EmptyStr;
BugReportHeader['registered owner'] := EmptyStr;
BugReportHeader['display mode'] := EmptyStr;
BugReportHeader['process id'] := EmptyStr;
BugReportHeader['largest free block'] := EmptyStr;
BugReportHeader['executable'] := EmptyStr;
BugReportHeader['compiled with'] := EmptyStr;
BugReportHeader['madExcept version'] := EmptyStr;
BugReportHeader['callstack crc'] := EmptyStr;
BugTxt := BugReport;
End;
AutoSaveBugReport(BugTxt + sLineBreak + MsgAux);
End;
Procedure IgnoreVclExceptions(Const exceptIntf: IMEException; Var handled: Boolean);
Begin
if exceptIntf.ExceptType = etFrozen then Begin
handled := True; // capture "Unknown"
handled := False; // capture "The application seems to be frozen"
P_LogException(Exception(exceptIntf.ExceptObject));
MessageBox(0, 'Frozen', PChar(Application.Title), MB_OK + MB_ICONWARNING);
End;
End;
Initialization
RegisterExceptionHandler(IgnoreVclExceptions, stDontSync, epQuickFiltering);
- Attachments
-
- Frozen MadExcept.7z
- (10.36 KiB) Not downloaded yet
Re: How do I show my custom message for freezing?
You can use "exceptIntf.BugReport" directly to get the bug report. That way the bug report doesn't have to be created twice.
Is that Windows.MessageBox or SomeVclUnit.MessageBox? Please prepend "Windows.", just to be safe that it's the Windows box, because the VCL MessageBox is not thread safe.
Is that Windows.MessageBox or SomeVclUnit.MessageBox? Please prepend "Windows.", just to be safe that it's the Windows box, because the VCL MessageBox is not thread safe.
Re: How do I show my custom message for freezing?
Much obliged.