Advertisement
jaclas

Untitled

Jun 23rd, 2020
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.59 KB | None | 0 0
  1. program onBeforeExceptionTest;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. {$R *.res}
  6.  
  7. uses SynCommons, SynLog, System.SysUtils;
  8.  
  9. type
  10.  TClassX = class
  11.    class function mormotLogOnBeforeException(const aExceptionContext: TSynLogExceptionContext;const aThreadName: RawUTF8): boolean;
  12.  end;
  13.  
  14. class function TClassX.mormotLogOnBeforeException(const aExceptionContext: TSynLogExceptionContext;const aThreadName: RawUTF8): boolean;
  15. var
  16.   i: Integer;
  17.   lCallStack : TRawUTF8DynArray;
  18.   s: RawUTF8;
  19. begin
  20.   Writeln('--- mormotLogOnBeforeException -------- begin --------');
  21.   Writeln('Exception class: ' + aExceptionContext.EClass.ClassName);
  22.   lCallStack := TSynMapFile.FindStackTrace(aExceptionContext);
  23.   for i := 0 to Length(lCallStack) - 1 do
  24.   begin
  25.     s := lCallStack[i];
  26.     Writeln('line #', i, ': ', s);
  27.   end;
  28.   Writeln('--- mormotLogOnBeforeException --------- end ----------');
  29.   Result := False  // not catch exception by mORMot
  30. end;
  31.  
  32. procedure InsideProc();
  33. begin
  34.   raise Exception.Create('test exception from inside procedure');
  35. end;
  36.  
  37. procedure OutsideProc();
  38. begin
  39.   InsideProc();
  40. end;
  41.  
  42. procedure VeryOutsideProc();
  43. begin
  44.   OutsideProc();
  45. end;
  46.  
  47. procedure Main;
  48. begin
  49.   TSynLog.Family.Level := LOG_VERBOSE;
  50.   TSynLog.Family.NoFile := True;
  51.   TSynLog.Family.EchoToConsole := LOG_VERBOSE;
  52.   TSynLog.Family.WithInstancePointer := False;
  53.   TSynLog.Family.OnBeforeException := TClassX.mormotLogOnBeforeException;
  54.   VeryOutsideProc();
  55. end;
  56.  
  57. begin
  58.   try
  59.     Main();
  60.   except
  61. //    on E: Exception do
  62. //      Writeln(E.ClassName, ': ', E.Message);
  63.   end;
  64.   Readln;
  65. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement