Converting TStackItem or TStackTrace to a string

delphi package - automated exception handling
Post Reply
MarkElder
Posts: 21
Joined: Sun Sep 10, 2006 3:42 am

Converting TStackItem or TStackTrace to a string

Post by MarkElder »

Hello,

I am Registering and Except Action Handler that needs to add a few Additional fields to the bug reports. These are pulled out into a custom script that adds the item to our ticketing system.

I'd like to add the main thread callstack (or better yet the first X lines of the call stack) to our description field. I was thinking there should be a utility function or some code I could copy to print the TStackItem as a string... but I can't seem to find it.

Does something exist or do I just need to roll my own?

Thanks,

Mark


Here is my function

Code: Select all

procedure MadExceptSetTitle(action: TExceptAction; const exceptIntf: IMEException; var handled: boolean);
{^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
begin
  if action <> eaSendBugReport2 then
    exit;

  exceptIntf.BeginUpdate;
  exceptIntf.AdditionalFields.Add('product', 'DataLog');
  exceptIntf.AdditionalFields.Add('subject', 'DataLog Except: ' + LeftStr(exceptIntf.ExceptMessage, 75));
  exceptIntf.AdditionalFields.Add('description', exceptIntf.ExceptMessage + '<br><br>'
                                               + exceptIntf.BugTrackerDescription + '<br><br>'
                                               + exceptIntf.Callstacks[0].ToString); // <<-- This is what I can't find. 
                                               //^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  exceptIntf.EndUpdate;

  handled := false;
end;
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Re: Converting TStackItem or TStackTrace to a string

Post by madshi »

You can use "exceptIntf.BugReportSections[0]" instead. This will be the crashing thread, which is usually (but not always) the main thread.
MarkElder
Posts: 21
Joined: Sun Sep 10, 2006 3:42 am

Re: Converting TStackItem or TStackTrace to a string

Post by MarkElder »

That got me looking in the right direction. I actually wanted the contents so I used this:

exceptIntf.BugReportSections[exceptIntf.BugReportSections.Items[0]]

There did not seem to be a way to get the "content" by index, but Items[0] gives me the name needed to get the content.

Thanks!
Post Reply