Advertisement
RandomClear

How to silently process exception

Oct 25th, 2014
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.90 KB | None | 0 0
  1. // See also: http://pastebin.com/9P0PJcyc - "how to ignore particular exception"
  2. // See also: http://pastebin.com/ACtr0r6S - "how to silently log 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.  
  11. // ...
  12.  
  13. var
  14.   EI: TEurekaExceptionInfo;
  15. begin
  16.   try
  17.     // ...
  18.   except
  19.     EI := ExceptionManager.LastThreadException;
  20.     // or:
  21.     EI := ExceptionManager.Info(ExceptObject, ExceptAddr);
  22.     // or:
  23.     on E: Exception do
  24.       EI := ExceptionManager.Info(E);
  25.  
  26.     LogException(EI);
  27.   end;
  28.  
  29. ...
  30.  
  31. procedure LogException(const AEI: TEurekaExceptionInfo);
  32. begin
  33.   if not Assigned(AEI) then
  34.     Exit;
  35.  
  36.   // The code below is just example.
  37.   // You may alter it to your liking.
  38.  
  39.   // Set options for "silent" exception
  40.   AEI.Options.ExceptionDialogType     := edtNone;  // no dialog
  41.   AEI.Options.SenderClasses           := '';       // no sending
  42.   AEI.Options.AutoCrashOperation      := tbNone;   // no autocrash counting
  43.   AEI.Options.SaveLogFile             := True;     // save bug report to disk
  44.   AEI.Options.ExceptionsFilters.Clear;             // ignore exception filters
  45.  
  46.   // Log each exception to individual files
  47.   if ExtractFileExt(AEI.Options.OutputPath) <> '' then // if report path contains file name - delete it
  48.     AEI.Options.OutputPath := ExtractFilePath(AEI.Options.OutputPath);
  49.   AEI.Options.loAddBugIDInLogFileName := True;
  50.   AEI.Options.loAddComputerNameInLogFileName := False;
  51.   AEI.Options.loAddDateInLogFileName  := False;
  52.   AEI.Options.soExcCount              := True;
  53.   AEI.Options.ErrorsNumberToSave      := 1;
  54.   AEI.Options.loNoDuplicateErrors     := True;
  55.   AEI.Options.soAppVersionNumber      := True;     // <- this assumes that you are using version info; comment this otherwise
  56.   AEI.Options.loDeleteLogAtVersionChange := True;  // <- this assumes that you are using version info; comment this otherwise
  57.   AEI.Options.loSaveProcessesSection  := False;
  58.  
  59.   // Log only exception in current thread
  60.   AEI.Options.boPauseRTLThreads       := False;
  61.   AEI.Options.boPauseWindowsThreads   := False;
  62.   AEI.Options.csoShowWindowsThreads   := False;
  63.   AEI.Options.csoShowRTLThreads       := False;
  64.   AEI.Options.csoShowELThreads        := False;
  65.  
  66.   // Handle this exception (save report, show dialog, send report, etc.)
  67.   ExceptionManager.Handle(AEI);
  68.  
  69.   // If AEI is last exception in current thread -
  70.   // then you can use ExceptionManager.ShowLastExceptionData
  71.   // instead of ExceptionManager.Handle.
  72. end;
  73.  
  74. // This code will perform normal processing of exception.
  75. // I.e. all features will be invoked (such as dialogs, sending, duplicate/count merging, etc.)
  76. // If you want to just log exception - see: http://pastebin.com/ACtr0r6S
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement