Root > How to... > ...ignore particular exception?

...ignore particular exception?

Previous pageReturn to chapter overviewNext page   

First, you have to identify exception which you want to ignore. You can identify exception by:

Exception class name;
Exception module;
Exception location:
oRoutine;
oLine;
oAddress or offset;
Exception message;
Exception thread;
Other information.

 

Once exception is identified - you can instruct EurekaLog to ignore this exception. You can:

Instruct EurekaLog to ignore this exception. Exception will be handled by RTL, as if EurekaLog was not installed;
Instruct EurekaLog to consider this exception as expected. EurekaLog will handle exception, but not show details, just message; See also for more details.
Instruct EurekaLog to "eat" exception. Exception will not be handled at all, it will disappear.

 

Note: you may want to mark exception as expected instead of ignoring it.

 

There are several available methods. Not all methods supports all of the features discussed above. This article covers the following options:

1. Use custom attributes
2. Use filters
3. Use event handlers
4. Use code to explicitly ignore exception

 

See also:

 

 

Option 1

Use custom attributes:

 

uses
  EClasses,
  ETypes;
 
type
  [EurekaLogHandler(fhtRTL)]
  ETestException = class(Exception);
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  // ETestException will be ignored by EurekaLog and
  // it always will be handled by your application
  // (as if EurekaLog would be disabled).
  // In other words, this will be catched by standard
  // Application.HandleException method.
  // A default MessageBox will be shown.
  raise ETestException.Create('Error Message');
end;

 

Another example:

 

uses
  EClasses;
 
type
  [EurekaLogExpected()]
  ETestException = class(Exception);
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  // ETestException will be handled by EurekaLog.
  // However, it would be considered as "expected".
  // In other words, this will be catched and shown by EurekaLog.
  // But (EurekaLog) error dialog will lack
  // "details", "send" and "restart" options.
  raise ETestException.Create('Error Message');
end;

 

Another example:

 

uses
  EClasses;
 
type
  [EurekaLogHandler(fhtNone)]
  ETestException = class(Exception);
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  // ETestException will be handled by EurekaLog.
  // However, it would be considered as ignored.
  // No dialog, no bug report, no sending.
  // Exception will act like EAbort.
  raise ETestException.Create('Error Message');
end;

 

Read more about this method.

 

 

Option 2

Use exception filters. Typically, you create exception filters at design-time:

 

 

Ignoring ETestException exception

(by using "RTL" handler)

 

However, you can also create exception filters manually from code:

 

uses
  EModules;
 
  CurrentEurekaLogOptions.ExceptionsFilters.AddIgnoredException(ETestException);
 
  // ETestException will be ignored by EurekaLog and
  // it always will be handled by your application
  // (as if EurekaLog would be disabled).
  raise ETestException.Create('Error Message');

 

Another example:

 

uses
  EModules;
 
  CurrentEurekaLogOptions.ExceptionsFilters.AddExpectedException(ETestException);
 
  // ETestException will be handled by EurekaLog.
  // However, it would be considered as expected.
  // "details", "send" and "restart" options will not be shown.
  raise ETestException.Create('Error Message');

 

Another example:

 

uses
  EModules;
 
  CurrentEurekaLogOptions.ExceptionsFilters.AddFullyIgnoredException(ETestException);
 
  // ETestException will be handled by EurekaLog.
  // However, it would be considered as ignored.
  // No dialog, no bug report, no sending.
  // Exception will act like EAbort.
  raise ETestException.Create('Error Message');

 

Another example:

 

uses
  EModules,
  ETypes;
 
// Create custom filter:
var
  Filter: TEurekaExceptionFilter;
begin
  FillChar(Filter, SizeOf(Filter), 0);
 
  Filter.Active := True;
  Filter.ExceptionClassName := ETestException.ClassName;
  Filter.ExceptionType := fetAll;
  Filter.DialogType := edtUnchanged;
  Filter.HandlerType := fhtRTL;
  Filter.ActionType := fatUnchanged;
 
  CurrentEurekaLogOptions.ExceptionsFilters.Add(Filter);
 
  // ETestException will be ignored by EurekaLog and
  // it always will be handled by your application
  // (as if EurekaLog would be disabled).
  raise ETestException.Create('Error Message');
end;

 

Read more about this method here.

 

 

Option 3

Use event handlers.

 

uses
  EEvents; // for RegisterEventExceptionNotify
 
type
  ETestException = class(Exception);
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  // ETestException will be ignored by EurekaLog and
  // it always will be handled by your application
  // (as if EurekaLog would be disabled).
  raise ETestException.Create('Error Message');
end;
 
procedure ExceptionNotify(const ACustom: Pointer; 

  AExceptionInfo: TEurekaExceptionInfo; 

  var AHandle: Boolean; 

  var ACallNextHandler: Boolean);
begin
  // Specify EurekaLog to ignore ETestException

  
  if // this check matches ETestException only, but skips child classes

     AExceptionInfo.ExceptionClass = ETestException.ClassName then 
  begin
    AHandle := False;
    ACallNextHandler := False;
    Exit;
  end;
end;
 
initialization
  RegisterEventExceptionNotify(nil, ExceptionNotify);
end.

 

Another example:

 

uses
  EEvents; // for RegisterEventExceptionNotify
 
type
  ETestException = class(Exception);
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  // ETestException will be handled by EurekaLog.
  // However, it would be considered as expected.
  // "details", "send" and "restart" options will not be shown.
  raise ETestException.Create('Error Message');
end;
 
procedure ExceptionNotify(const ACustom: Pointer; 

  AExceptionInfo: TEurekaExceptionInfo; 

  var AHandle: Boolean; 

  var ACallNextHandler: Boolean);
begin
  // Mark exception as expected, but allow it to be handled by EurekaLog.
  if (AExceptionInfo.ExceptionObject <> niland
     (AExceptionInfo.ExceptionNative) and

     // this check matches ETestException and any of its child classes
     (Exception(AExceptionInfo.ExceptionObject).InheritsFrom(ETestException)) and 
     (AExceptionInfo.ExceptionMessage = 'Error Message'then
  begin
    AExceptionInfo.ExpectedContext := -1;
    Exit;
  end;
end;
 
initialization
  RegisterEventExceptionNotify(nil, ExceptionNotify);
end.

 

Here is an example of how you can check various properties of your exception:

 

procedure ExceptionNotify(const ACustom: Pointer; 

  AExceptionInfo: TEurekaExceptionInfo; 

  var AHandle: Boolean; 

  var ACallNextHandler: Boolean);
begin

  if // check that there is exception object

     (AExceptionInfo.ExceptionObject <> niland 

     // check that it is a Delphi/Builder object
     (AExceptionInfo.ExceptionNative) and 

     // check exception class
     (Exception(AExceptionInfo.ExceptionObject).InheritsFrom(EOSError)) and 

     // check any additional exception properties
     (EOSError(AExceptionInfo.ExceptionObject).ErrorCode = ERROR_ACCESS_DENIED) and 

     // check exception class
     (AExceptionInfo.ExceptionClass = 'EOSError'and 

     // check exception message
     (AExceptionInfo.ExceptionMessage = 'Access Denied'and 

     // check call stack
     (AExceptionInfo.CallStack.Count > 0) and 
     (AExceptionInfo.CallStack[0].Location.UnitName = 'ServiceProvider'and
     (AExceptionInfo.CallStack[0].Location.ProcedureName = 'Connect'and

     // check exception address
     (AExceptionInfo.Address = $00456789) and 

     // check exception module
     (AExceptionInfo.Module = $00400000) and 

     // check exception module name
     SameFileName(ExtractFileName(AExceptionInfo.ModuleName), 'Project1.exe'and 

     // check exception thread
     (AExceptionInfo.ThreadID = MainThreadID) and 

     // check for known BugID
     (AExceptionInfo.BugID = $E36F0000) and 

     // check for handler (what hook has catched the exception)
     (AExceptionInfo.Handler = atVCL) and 

     // check for misc. props
     AExceptionInfo.Handled and 
     AExceptionInfo.SafeCallExpt and
     AExceptionInfo.ThreadException
     AExceptionInfo.InitializationException then
  begin
    // ...
    Exit;
  end;
end;

 

Read more about this method here.

 

 

Option 4

Disable EurekaLog for the duration of the exception in question.

 

SetEurekaLogStateInThread(0, False);
try
  SomeStrVar := StrToInt(SomeIntVar);
finally
  SetEurekaLogStateInThread(0, True);
end;

 

Or simply hide the exception with an explicit try/except block:

 

try
  SomeStrVar := StrToInt(SomeIntVar);
except
  SomeStrVar := -1;
end;

 

 

See also:




Send feedback... Build date: 2018-11-26
Last edited: 2018-11-12
PRIVACY STATEMENT
The documentation team uses the feedback submitted to improve the EurekaLog documentation. We do not use your e-mail address for any other purpose. We will remove your e-mail address from our system after the issue you are reporting has been resolved. While we are working to resolve this issue, we may send you an e-mail message to request more information about your feedback. After the issues have been addressed, we may send you an email message to let you know that your feedback has been addressed.


Permanent link to this article: https://www.eurekalog.com/help/eurekalog/how_to_ignore_particular_exception.php