Root > How to... > ...get exception info?

...get exception info?

Previous pageReturn to chapter overviewNext page   

Exception info is represented by TEurekaExceptionInfo class from EException unit.

 

Important: EurekaLog has to be enabled for this to work. See also.

 

 

Option 1

Assuming you are inside EurekaLog's event handler - this information is passed as argument:

 

uses
  EEvents;
 
procedure MyExceptionNotifyHandler(const ACustom: Pointer; 

  AExceptionInfo: TEurekaExceptionInfo; // <- here

  var AHandle: Boolean; 

  var ACallNextHandler: Boolean);
begin
  // use AExceptionInfo

  // ...
end;
 
initialization
  RegisterEventExceptionNotify(nil, MyExceptionNotifyHandler);
end.

 

 

Option 2

Assuming you have access to RTL's exception object:

 

uses
  EExceptionManager, // for ExceptionManager
  EException;        // for TEurekaExceptionInfo 
 
var
  EI: TEurekaExceptionInfo;
// ...
  except
    on E: Exception do
    begin
      EI := ExceptionManager.Info(E);

      // EI could be nil if EurekaLog is disabled or

      // if exception is ignored by EurekaLog

      if Assigned(EI) then 

        // ...
    end;
  end;

 

Note: due to bugs in some older IDEs, you may need to write like this:

      EI := ExceptionManager.Info(Pointer(E));

 

 

Option 3

Assuming you want exception info for last (most recent) exception in current thread:

 

uses
  EExceptionManager, // for ExceptionManager
  EException;        // for TEurekaExceptionInfo 

 
var
  EI: TEurekaExceptionInfo;
begin
  EI := ExceptionManager.LastThreadException;
  // ...
end;

 

 

Checking exception's info

Once you have obtained a TEurekaExceptionInfo instance - you can read various properties. Below is an example of different checks that you can use.

 

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

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

     // check that there is an exception object

     (AExceptionInfo.ExceptionObject <> niland 

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

     // check exception class 

     // (only for .ExceptionNative = True and .ExceptionObject <> nil)
     (TObject(AExceptionInfo.ExceptionObject).InheritsFrom(EOSError)) and 

     // IMPORTANT NOTE: Please note that the .ExceptionObject may be unavailable even for Delphi exceptions!

     // For example, if the exception object was already deleted:

     //

     // try

     //   raise Exception.Create('Inner Exception'); // - will be deleted

     // except

     //   on E: Exception do

     //     raise Exception.Create('Outer Exception');

     // end; 

     // 

     // See also.

     // That is why we check for NIL in the example above.

     // For this reason we highly recommend to use properties of AExceptionInfo when possible,

     // Such as .ExceptionClass and .ExceptionMessage

 

     // check any additional exception properties
     (EOSError(AExceptionInfo.ExceptionObject).ErrorCode = ERROR_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 = Pointer($00456789)) and 

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

     (AExceptionInfo.Module = HInstance) 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
     (not AExceptionInfo.Handled) and 
     AExceptionInfo.SafeCallExpt and
     AExceptionInfo.ThreadException
     AExceptionInfo.InitializationException then
  // ...

 

The code above is only an example, you don't need to write it all.

 

 

See also:




Send feedback... Build date: 2024-09-30
Last edited: 2023-08-09
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_get_exception_info.php