Advertisement
RandomClear

How to get call stack for last exception

May 20th, 2015
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.11 KB | None | 0 0
  1. // See also: http://pastebin.com/46QkwZNi - "how to convert call stack to text"
  2. // See also: http://pastebin.com/rdNbEwPH - "how to get call stack on demand"
  3. // See also: http://pastebin.com/ACtr0r6S - "how to silently log exception"
  4. // See also: http://pastebin.com/sBn3PA1r - "how to create hang/deadlock report on demand"
  5.  
  6. // Option 1:
  7.  
  8. except
  9.   on E: Exception do
  10.     Memo1.Lines.Text := E.StackTrace;
  11. end;
  12.  
  13. // Option 2:
  14.  
  15. uses
  16.   EExceptionManager,
  17.   EException;
  18.  
  19. var
  20.   EI: TEurekaExceptionInfo;
  21. begin
  22.   EI := ExceptionManager.LastThreadException;
  23.   if Assigned(EI) then // EI would be nil, if EurekaLog is disabled or event handlers instruct EurekaLog to skip this exception
  24.     Memo1.Lines.Text := EI.CallStack.ToString;
  25. end;
  26.  
  27. // Option 3:
  28.  
  29. uses
  30.   EExceptionManager,
  31.   EException;
  32.  
  33. var
  34.   EI: TEurekaExceptionInfo;
  35. // ...
  36.   except
  37.     on E: Exception do
  38.     begin
  39.       EI := ExceptionManager.Info(E);
  40.       if Assigned(EI) then // EI would be nil, if EurekaLog is disabled or event handlers instruct EurekaLog to skip this exception
  41.         Memo1.Lines.Assign(EI.CallStack);
  42.     end;
  43.   end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement