Stacktrace in Borland c++ builder 6

delphi package - automated exception handling
Post Reply
smokeman909
Posts: 1
Joined: Fri Dec 16, 2005 7:22 pm

Stacktrace in Borland c++ builder 6

Post by smokeman909 »

Hi, I am new to madexception and I am trying to run and see a stacktrace.

My borland succesfully compiles link and execute (after I copied the required .bpl files in my executables's folder)

I declare this in one of my method (In the OnClick event of a button)

TPStackTrace * trace = new TPStackTrace();

when I look at this object it seems ok in the debugger but I am trying to use
trace->StackTrace(); but it does not let me compile.

How do I use the object stacktrace?

I am trying to have a stacktrace, because in my application, I need to see wich object has created an instance of one of my base class in certain conditions..

thanks for any help

Simon
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

"TPStackTrace" is not an object. You should simply use the "StackTrace" function which gives you a stack trace string back. Or do you need the stack trace in structure form?

One problem with StackTrace() is that it when you want to use it to get an exception's callstack, you need to know the exception address and give it in. Unfortunately BCB doesn't want to tell you what the current exception address is (SysUtils.ExceptAddr() always returns NULL).

So to solve this problem I've exported a function from madExcept in the latest beta build named:

madExcept 3.0b beta 1 now exports a function named
"CheckExceptParams":

Code: Select all

procedure CheckExceptParams (var exceptObject  : TObject;
                             var exceptAddr    : pointer;
                             var preparedStack : pointer;
                             var context       : PContext);
This function will give you the exception parameters
when being called inside of a BCB try..catch statement.
You can use them to call "StackTrace". Give in the
exceptAddr value as the "currentAddr" into "StackTrace"
and set the "isException" parameter to true.

Here's the download of the latest madCollection beta:

http://madshi.net/madCollectionBeta.exe

It should look something like this then, I think:

Code: Select all

   System::TObject exceptObject;
   void exceptAddr;
   void preparedStack;
   Windows::TContext context;
   CheckExceptParams(&exceptObject, &exceptAddr, &preparedStack,
&context);
   ShowMessage(StackTrace(false, false, false, NULL, exceptAddr, true));
Post Reply