Using StackTrace

delphi package - automated exception handling
Post Reply
Questor
Posts: 2
Joined: Thu Nov 23, 2006 3:29 am

Using StackTrace

Post by Questor »

Hello,

I have server application for which I have started using MadExcept. I need to handle all my exceptions so the server can continue to function in the event of an error, but I want to log the callstack to my error file when they occur. The problem I am having is this:

try

Code: Select all


except
    on E: Exception do begin
      LogError('Exception: ' + E.Message + '.' + StackTrace);
    end;
end;

StackTrace is reporting the line "LogError" is on instead of the line in the code block where the exception occured (which is the information I really need to know).  Is there a way to do this?

Thanks in advance.
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Why don't you simply turn the exception dialog off and activate the "automatically continue application" switch? This way you wouldn't have to write any code yourself.

If you want to use StackTrace manually, you need to fill in some parameters. E.g. give in "ExceptAddr" as the parameter "currentAddr" and set the "isException" parameter to true.
Questor
Posts: 2
Joined: Thu Nov 23, 2006 3:29 am

Thanks!

Post by Questor »

madshi wrote:Why don't you simply turn the exception dialog off and activate the "automatically continue application" switch? This way you wouldn't have to write any code yourself.
Because then MadExcept would only log exceptions that I don't handle, correct? I need to handle these errors in these locations to prevent problems with later code execution, but in those cases I also want to log the call stack.
madshi wrote:If you want to use StackTrace manually, you need to fill in some parameters. E.g. give in "ExceptAddr" as the parameter "currentAddr" and set the "isException" parameter to true.
This solved my problem and everything looks great, thank you very much! :)
Post Reply