delphi package - automated exception handling
luciano_f
Posts: 47 Joined: Thu Feb 01, 2018 5:11 pm
Post
by luciano_f » Mon Feb 05, 2018 8:30 pm
I made the following code:
Code: Select all
Var I : Integer;
Var madSettings: IMEModuleSettings;
Begin
Try
I := StrtoInt('AAA');
Except
madSettings := MESettings();
madSettings.ListThreads := false;
madSettings.ShowCpuRegisters := false;
madSettings.ShowStackDump := false;
madSettings.ShowDisAsm := false;
madSettings.ShowRelativeAddrs := true;
madSettings.ShowRelativeLines := true;
CreateBugReport(etNormal, nil, nil, 0, 0, 0, nil, false, madSettings);
End
But this code does not save in the file "bugreport.txt"
What should I do to get this code saved in the Txt file?
luciano_f
Posts: 47 Joined: Thu Feb 01, 2018 5:11 pm
Post
by luciano_f » Tue Feb 06, 2018 10:12 am
I was able to solve using the following code below
Var I : Integer;
Var madSettings: IMEModuleSettings;
Var BugTxt : String;
Begin
Try
I := StrtoInt('AAA');
Except
madSettings := MESettings();
madSettings.ListThreads := false;
madSettings.ShowCpuRegisters := false;
madSettings.ShowStackDump := false;
madSettings.ShowDisAsm := false;
madSettings.ShowRelativeAddrs := true;
madSettings.ShowRelativeLines := true;
madSettings.AutoSave := True;
BugTxt := CreateBugReport(etNormal, nil, nil, 0, 0, 0, nil, false, madSettings);
AutoSaveBugReport(BugTxt, madSettings);
End
luciano_f
Posts: 47 Joined: Thu Feb 01, 2018 5:11 pm
Post
by luciano_f » Wed Feb 07, 2018 5:02 pm
I found a problem in this code I showed above.
It can not clear the data of BugReportHeader where I do with this code below :
The AutoSaveBugReport command ignores this code below and saves all the headers :
procedure RemoveCommandLineHeaderInfo(const exceptIntf : IMEException; var handled : boolean);
begin
exceptIntf.BugReportHeader['registered owner'] := EmptyStr;
exceptIntf.BugReportHeader['display mode'] := EmptyStr;
exceptIntf.BugReportHeader['process id'] := EmptyStr;
exceptIntf.BugReportHeader['allocated memory'] := EmptyStr;
exceptIntf.BugReportHeader['largest free block'] := EmptyStr;
exceptIntf.BugReportHeader['executable'] := EmptyStr;
exceptIntf.BugReportHeader['compiled with'] := EmptyStr;
exceptIntf.BugReportHeader['madExcept version'] := EmptyStr;
exceptIntf.BugReportHeader['callstack crc'] := EmptyStr;
handled := False;
end;
initialization
RegisterExceptionHandler(RemoveCommandLineHeaderInfo, stDontSync);
luciano_f
Posts: 47 Joined: Thu Feb 01, 2018 5:11 pm
Post
by luciano_f » Thu Feb 08, 2018 10:43 am
After much searching I was able to solve with the following code ::
Code: Select all
Procedure TForm1.Proc_LogErro(E : Exception);
Var madSettings: IMEModuleSettings;
Var exceptIntf : IMEException;
Var BugTxt : String;
Begin
madSettings := MESettings();
madSettings.ListThreads := false;
madSettings.ShowCpuRegisters := false;
madSettings.ShowStackDump := false;
madSettings.ShowDisAsm := false;
madSettings.ShowRelativeAddrs := true;
madSettings.ShowRelativeLines := true;
madSettings.AutoSave := True;
madSettings.ShowPleaseWaitBox := False;
With NewException(etHidden, E, nil, True, 0, 0, 0, 0, madSettings) do begin
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, madSettings);
End;
madshi
Site Admin
Posts: 10754 Joined: Sun Mar 21, 2004 5:25 pm
Post
by madshi » Mon Feb 12, 2018 6:54 pm
Generally, "MESettings()" gives you access to the global settings. So if you change that, you change it for all future exceptions. If you just want to change the settings for the one "save bug report" action, it makes more sense to use "NewException()" (as you already did), and then change all the settings on the IMEException interface. So I'd suggest that you don't use MESettings() in your code at all. Instead move the "ListThreads := false" and all the other things into the "with NewException()" block. The IMEException interface returned by NewException() inherits from the IMESettings interface, so you can change all the settings directly in the NewException() returned interface. Doing that will then only affect this one "save bug report" action, but will not modify the global settings.
luciano_f
Posts: 47 Joined: Thu Feb 01, 2018 5:11 pm
Post
by luciano_f » Sun Feb 18, 2018 11:29 am
I got grateful for the information.