EurekaLog automatically catches any unhandled exceptions in your application. However, you may want to force-handle exception coming from a specific code:
try
EurekaLog is a Delphi library. As such - it does not have direct access to C++ code. It means that C++ standard exceptions, as well as user-defined C++ exceptions, cannot be handled by the Delphi run time. Therefore Delphi's ExceptObject and ExceptAddr functions will return nil (NULL). Hence the EurekaLog will also see no exception.
If C++ Exceptions are not explicitly caught (in other words: there is no try-catch block), they are eventually caught by Delphi exception handlers (RTL or VCL code). When the Delphi RTL encounters an exception that is not Delphi generated or hardware related, the exception is mapped as an EExternalException. So, if a C++ exception is not explicitly caught and it leaks into the Delphi run time, the application raises an External Exception EEFFACE. Once that happens, EurekaLog steps in and handles this External Exception EEFFACE as a standard Delphi exception. For example:
try // E is the EExternalException (a Delphi exception) with the 0x0EEFFACE error code
If this is the case - you can follow the How to handle an exception guide.
In any other cases when:
you should wrap your C++ code in a Delphi code. For example, you can create the following Delphi unit:
unit DelphiTools;
The main idea here is to call your C++ code from a Delphi code, so you can use Delphi's try-except block.
This code is just an example. You can adjust it or write your own code. Specifically, you can replace the content of the except block. We just call a default RTL exception handler in the above example, but you may add any custom processing that you want.
Once you have such code, you can do the following:
[BEFORE] (old code, which should be replaced)
try
This code will run your C++ code from the ASampleFunc function inside a Delphi try-except block. Therefore, any C++ exceptions thrown by your code will be wrapped by Delphi RTL into a Delphi exception object (EExternalException) - which can be catched and handled by EurekaLog.
See also:
|