Dave Craggs 3 Posted Wednesday at 11:12 AM 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
Der schöne Günther 230 Posted Wednesday at 11:29 AM (edited) 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: JEDI Code Library (the JclDebug and the JCLHoohExcept unit). EurekaLog madExcept 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 Wednesday at 11:29 AM by Der schöne Günther Share this post Link to post
Lars Fosdal 1357 Posted Wednesday at 11:36 AM Or, you invest in EurekaLog or MADExcept. Share this post Link to post
aehimself 325 Posted Wednesday at 11:50 AM There are also open-source alternatives: https://github.com/MahdiSafsafi/DebugEngine https://github.com/Fr0sT-Brutal/Delphi_StackTraces I never used JCL as I only wanted stack traces and I had to import half of the library just to achieve that. Share this post Link to post
Dave Craggs 3 Posted Wednesday at 02:44 PM I have been using MadExcept for years. So how do I plug it into DunitX? Share this post Link to post
Dave Craggs 3 Posted Wednesday at 03:02 PM Hmm - there is a unit DUnitX.StackTrace.MadExcept5; Share this post Link to post
Dave Craggs 3 Posted Wednesday at 03:24 PM Think I am losing it. Was also discussed here - no resolution though. Share this post Link to post
Dave Craggs 3 Posted Wednesday at 04:12 PM 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. Share this post Link to post