RandomClear icon

How to silently log exception

RandomClear | PRO | 11/03/14 10:23:52 PM UTC | 0 ⭐ | 9091 👁️ | Never ⏰ | []
Delphi |

1.78 KB

|

None

|

0 👍

/

0 👎

// See also: http://pastebin.com/9P0PJcyc - "how to ignore particular exception"
// See also: http://pastebin.com/XWpyDuw6 - "how to silently process exception"
// See also: http://pastebin.com/QiicyV2E - "how to log all (handled) exceptions"
// See also: http://pastebin.com/rdNbEwPH - "how to get call stack on demand"
// See also: http://pastebin.com/46QkwZNi - "how to convert call stack to text"
 
uses
  EException
  EExceptionManager,
  ELogBuilder,
  ESysInfo;
 
// ...
 
var
  EI: TEurekaExceptionInfo;
begin
  try
    // ...
  except
    EI := ExceptionManager.LastThreadException;
    // or:
    EI := ExceptionManager.Info(ExceptObject, ExceptAddr);
    // or:
    on E: Exception do
      EI := ExceptionManager.Info(E);
 
    LogException(EI);
  end;
 
...
 
procedure LogException(const AEI: TEurekaExceptionInfo);
var
  LogBuilder: TBaseLogBuilder;
  LogFileName: String;
begin
  // Create a generator for log content. 
  // You may use default class for your application (LogBuilderClass)
  // Or a specific class (TLogBuilder, TXMLLogBuilder or your own descendant)
  LogBuilder := LogBuilderClass.Create(AEI);  
  try
    // File name to save bug report to.
    // You may use AEI.BugIDStr, if you want to save each report into individual file.
    LogFileName := ExpandEnvVars(AEI.Options.OutputLogFile(''));
    // Generate and save bug report. File will be overwritten.
    LogBuilder.SaveToFile(LogFileName);
  finally
    FreeAndNil(LogBuilder);
  end;
end;
 
// This code will save bug report about exception to the specified file. 
// No other features will be invoked (such as dialogs, sending, duplicate/count merging, etc.)
// If you want to process exception (like to get duplicate/count merging feature) - see: http://pastebin.com/XWpyDuw6

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎