views:

454

answers:

4

Using Delphi 7, how can I get a string representing the stack-trace from an Exception?

try
  SomethingDodgy();
except
  on E:Exception do begin
    // print stack trace
    Log.Write(/* ??? */);
  end;
end;

I hear there's a GetStackTrace function in the latest delphi, but I can't find anything for delphi 7. No, upgrading is not an option :)

A: 

The stack-trace in Win32 is not as good as .NET's or Java's (and the latest versoin of Delphi uses .NET stack trace).
Anyway, I found one link that provides more information on it here (It is at ExeEx so to allow to view that solution click the first link on the search).

See the bottom of the page there.

Dmytrii Nagirniak
-1. Experts Exchange: "All comments and solutions are available to Premium Service Members only."
Rob Kennedy
I told you read at the BOTTOM!There are solutions.Please read properly before downvoting!
Dmytrii Nagirniak
@Dmitriy: No there are no solutions. Not at the bottom and not anywhere else.
Smasher
ExEx is sneaky. If you google for the URL, and then click the link from google, your referer will be google, and they will show you the solutions.
Blorgbeard
The sooner SO kills them, the better.
Blorgbeard
@Blorgbeard, thanks for pointing that out. SO is already killing it :)
Dmytrii Nagirniak
@Dmitriy - EE will only display the answers at the bottom in certain web browsers (ie, *not* IE ;)
moobaa
@moobaa, ohh my ... That is so ridiculous!
Dmytrii Nagirniak
I just tried it with Firefox and IE7 - I get different pages but both show the answers at the bottom. Re "killing EE": +1 :-)
Ulrich Gerhardt
+13  A: 

You could try using madExcept, a wonderful Exception handling framework.

madshi has heaps of sample code in there; I'm sure I've used the stack-trace stuff in there before.

As Dmitriy noted, the JCL also has stack-trace code; an old sample is here.

moobaa
Yeah, madExcept is awesome - but this is commercial code I'm writing, and I don't think I can get the company to buy madExcept right now. JCL sounds good too though, I will take a look..
Blorgbeard
It's not all that expensive. How many hours of work should you spend working around this??
Loren Pechtel
Yeah - but the stack trace is a nice-to-have in this project, so I won't spend much time trying to work around it.
Blorgbeard
JCL DEBUG works very good for me.
Edwin
+1  A: 

MemChk is pretty easy to use (especially to search/find memory leaks) and knows how to render a stack trace from a code address.

Stijn Sanders
+5  A: 

I throw EurekaLog in the game. It's a great tool and not expensive at all.

Smasher