Currently evaluating madExcept, trying to understand how best to do the following things:
Catch all exceptions/leaks etc. program wide
Show no madExcept dialogs, send no madExcept emails, save no madExcept files etc.
Store the complete text of all exceptions/leaks from all threads/objects etc. in variable(s)
Programmatically, conditionally control the three "final options": Continue App/Close App/Restart App
We want to surface our own exception/leak dialogs.
Here are my feeble attempts so far:
Code: Select all
program TestApp;
uses
madExcept,
madLinkDisAsm,
madListHardware,
madListProcesses,
madListModules,
Vcl.Forms,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
begin
RegisterExceptionHandler(TWSExceptHandler.madExceptionHandler,stTrySyncCallAlways);
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
unit Unit1;
interface
uses
madExcept,
madExceptVcl,
...
type
TWSExceptHandler = class
public
class procedure madExceptionHandler(const exceptIntf: IMEException; var handled: Boolean);
end;
TForm1 = class(TForm)
...
end;
var
Form1: TForm1;
madExcept: TMadExceptionHandler;
implementation
{$R *.dfm}
uses
...
madTypes,
madStackTrace,
...
const
KStackTraceHeader: UnicodeString = 'Module Name |Unit Name |Function Name |Line #|Relative Line #';
class procedure TWSExceptHandler.madExceptionHandler(const exceptIntf: IMEException; var handled: Boolean);
function FormatColumn(const colValue: UnicodeString): UnicodeString;
begin
Result := colValue;
if Length(colValue) < 32 then
while Length(Result) < 32 do
Result := Result + #32;
end;
var
stackTrace: TStackTrace;
stackItem: TStackItem;
i,n: Integer;
s: UnicodeString;
begin
s := KStackTraceHeader;
i := 0;
while SizeOf(stackTrace) > SizeOf(TStackTrace) do
begin
stackTrace := exceptIntf.Callstacks[i];
for n := 0 to Pred(Length(stackTrace)) do
begin
stackItem := stackTrace[n];
with stackItem do
s := s + FormatColumn(ModuleName) + ' | ' + FormatColumn(UnitName) + ' | ' + FormatColumn(FunctionName) + ' | ' + FormatColumn(IntToStr(Line)) + ' | ' + FormatColumn(IntToStr(RelLine)) + #13#10;
end;
for n := 1 to Length(KStackTraceHeader) do
s := s + '_';
inc(i);
end;
ShowMessage(s);
end;
initialization
madExcept := TMadExceptionHandler.Create(Nil);
madExcept.OnException := TWSExceptHandler.madExceptionHandler;
finalization
madExcept.Free;
end.
Thanks.