Advertisement
RandomClear

How to silently log exception

Nov 3rd, 2014
656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.78 KB | None | 0 0
  1. // See also: http://pastebin.com/9P0PJcyc - "how to ignore particular exception"
  2. // See also: http://pastebin.com/XWpyDuw6 - "how to silently process exception"
  3. // See also: http://pastebin.com/QiicyV2E - "how to log all (handled) exceptions"
  4. // See also: http://pastebin.com/rdNbEwPH - "how to get call stack on demand"
  5. // See also: http://pastebin.com/46QkwZNi - "how to convert call stack to text"
  6.  
  7. uses
  8.   EException
  9.   EExceptionManager,
  10.   ELogBuilder,
  11.   ESysInfo;
  12.  
  13. // ...
  14.  
  15. var
  16.   EI: TEurekaExceptionInfo;
  17. begin
  18.   try
  19.     // ...
  20.   except
  21.     EI := ExceptionManager.LastThreadException;
  22.     // or:
  23.     EI := ExceptionManager.Info(ExceptObject, ExceptAddr);
  24.     // or:
  25.     on E: Exception do
  26.       EI := ExceptionManager.Info(E);
  27.  
  28.     LogException(EI);
  29.   end;
  30.  
  31. ...
  32.  
  33. procedure LogException(const AEI: TEurekaExceptionInfo);
  34. var
  35.   LogBuilder: TBaseLogBuilder;
  36.   LogFileName: String;
  37. begin
  38.   // Create a generator for log content.
  39.   // You may use default class for your application (LogBuilderClass)
  40.   // Or a specific class (TLogBuilder, TXMLLogBuilder or your own descendant)
  41.   LogBuilder := LogBuilderClass.Create(AEI);  
  42.   try
  43.     // File name to save bug report to.
  44.     // You may use AEI.BugIDStr, if you want to save each report into individual file.
  45.     LogFileName := ExpandEnvVars(AEI.Options.OutputLogFile(''));
  46.     // Generate and save bug report. File will be overwritten.
  47.     LogBuilder.SaveToFile(LogFileName);
  48.   finally
  49.     FreeAndNil(LogBuilder);
  50.   end;
  51. end;
  52.  
  53. // This code will save bug report about exception to the specified file.
  54. // No other features will be invoked (such as dialogs, sending, duplicate/count merging, etc.)
  55. // If you want to process exception (like to get duplicate/count merging feature) - see: http://pastebin.com/XWpyDuw6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement