Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program onBeforeExceptionTest;
- {$APPTYPE CONSOLE}
- {$R *.res}
- uses SynCommons, SynLog, System.SysUtils;
- type
- TClassX = class
- class function mormotLogOnBeforeException(const aExceptionContext: TSynLogExceptionContext;const aThreadName: RawUTF8): boolean;
- end;
- class function TClassX.mormotLogOnBeforeException(const aExceptionContext: TSynLogExceptionContext;const aThreadName: RawUTF8): boolean;
- var
- i: Integer;
- lCallStack : TRawUTF8DynArray;
- s: RawUTF8;
- begin
- Writeln('--- mormotLogOnBeforeException -------- begin --------');
- Writeln('Exception class: ' + aExceptionContext.EClass.ClassName);
- lCallStack := TSynMapFile.FindStackTrace(aExceptionContext);
- for i := 0 to Length(lCallStack) - 1 do
- begin
- s := lCallStack[i];
- Writeln('line #', i, ': ', s);
- end;
- Writeln('--- mormotLogOnBeforeException --------- end ----------');
- Result := False // not catch exception by mORMot
- end;
- procedure InsideProc();
- begin
- raise Exception.Create('test exception from inside procedure');
- end;
- procedure OutsideProc();
- begin
- InsideProc();
- end;
- procedure VeryOutsideProc();
- begin
- OutsideProc();
- end;
- procedure Main;
- begin
- TSynLog.Family.Level := LOG_VERBOSE;
- TSynLog.Family.NoFile := True;
- TSynLog.Family.EchoToConsole := LOG_VERBOSE;
- TSynLog.Family.WithInstancePointer := False;
- TSynLog.Family.OnBeforeException := TClassX.mormotLogOnBeforeException;
- VeryOutsideProc();
- end;
- begin
- try
- Main();
- except
- // on E: Exception do
- // Writeln(E.ClassName, ': ', E.Message);
- end;
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement