Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass call stack information to an exception using EurekaLog?

I have a threaded application and for some purpose I want to pass call stack information of a catched exception to a new custom exception:

try
    //here an unknown exception is rissen
except 
    on E: Exception do
    begin
        if ... then
          raise EMyException.Create(E, CallStackOfExceptionEAsString);
    end;
end;

What is the best way to do this, preferably using EurekaLog? I am using Delphi 2006 btw.

like image 574
Alois Heimer Avatar asked Dec 03 '25 06:12

Alois Heimer


1 Answers

EurekaLog exposes several event handlers like OnExceptionNotify.

You can implement these in your code. For example: procedure EurekaLogExceptionNotify( EurekaExceptionRecord: TEurekaExceptionRecord; var Handled: Boolean);

Here you can see a TEurekaExceptionRecord which is defined in ExceptionLog.pas. But you maybe just own the non-source version which works just fine.

The record has a EurekaExceptionRecord.CallStack list. This proprietary list can be converted to TStringsusing the CallStackToStrings method which is also defined in the ExceptionLog unit.

Here is an example where I write the CallStack into a StringList.

CallStackList := TStringList.Create;
try
  CallStackToStrings(EurekaExceptionRecord.CallStack, CallStackList);

  LogMessage := 'An unhandled exception occured. Here is the CallStack.' + #13#10
    + CallStackList.Text;
finally
  CallStackList.Free;
end;

At least from this starting point you should be able to investigate the exposed functions, records etc.. All information is accessible.

like image 186
Erik Virtel Avatar answered Dec 06 '25 01:12

Erik Virtel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!