Jump to content
Dave Craggs

StacTrace

Recommended Posts

How do you get a StackTrace when an exception occurs?

 

I have implement a logger inheriting from TDUnitXNullLogger

 

Got this in OnTestError

 

procedure TJPANUllLogger.OnTestError(const threadId: TThreadID;
  const Error: ITestError);
begin
  inherited;
  FCurrentTestItem.Error := True;
  FCurrentTestItem.StackTrace := Error.StackTrace;
  Codesite.SendFmtMsg('StackTrace %s',[Error.StackTrace]);
  Codesite.SendFmtMsg('Message %s',[Error.ExceptionMessage]);
  Codesite.SendFmtMsg('LocationInfo %s',[Error.ExceptionLocationInfo]);
  Codesite.SendFmtMsg('AddressInfo %s',[Error.ExceptionAddressInfo]);
end; 

ExceptionMessage is coming through, but not StackTrace

Share this post


Link to post

The StackTrace property is just a placeholder, it is always empty. There is no built-in way to get the stacktrace. Hard to believe, but here is what the official documentation says:

 

System.SysUtils.Exception.StackTrace - RAD Studio API Documentation (embarcadero.com)

Quote

By default, StackTrace is always an empty string. 

(...)

In order to use the StackTrace property to obtain the stack trace for exceptions, you have to use (or implement) a stack trace provider. There are a number of third-party solutions, both commercial and free.

Some of the stack trace providers are:

For more information on how to use some of the above third-party stack trace providers, see the following blog posts:

(...)

A few years ago, I used the Jedi Code library. After that, I completely removed the JCL from our products and since then, I am just using the "FastMM_FullDebugMode.dll" which exports a few handy methods that will give you the stack trace as a string list.

Edited by Der schöne Günther

Share this post


Link to post

OK got it working. Needed to include 


{$I DUnitX.Stacktrace.inc}

 

Needed to be edited to enable MadExcept5

 

Also needed to add DUnitX.StackTrace.MadExcept5 to the project.

image.png

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×