0

Is it possible to obtain a stack trace of an exception at runtime from the included CodeSite express? If so, does anyone have any experience with, or examples of, doing this?

Failing that, is there a way to achieve this with an open source library?

I introduced logging to a 10+ year old Delphi application, so there's still a considerable proportion of the application without logging. So for areas that are yet to be rewritten, I have an Application.OnException hook. It would be very useful to have a meaningful stack trace of the sporadic access violations we get in production. Below is what I already have, and I was disappointed to find the StackTrace property empty.

class procedure Log.Error(const err: Exception; const method: string);
begin
   FileLog(err, method);
end;

class procedure Log.FileLog(const err: Exception; const method: string);
var
_msg: TStringList;
begin
   //_msg := Format('%s Failed:%3:s%1:s%3:s %2:s%3:s', [PreparedEntry(method), err.Message, err.StackTrace, sLineBreak]);
   _msg := PreparedEntry( Format('%s Failed:', [method]));
   _msg.Add(err.Message);
   _msg.Add(err.StackTrace);
  WriteLog(_msg, _logFileName);
end;

We are in an advanced stage of migrating from a delphi win32 application to a multi-tiered .net wcf server application still serving the delphi client application. The long and short of this is that after convincing management to purchase Delphi XE5 (just to get the improved json support and live bindings) asking for another delphi purchase is very hard to justify.

Thanks

reckface
  • 5,678
  • 4
  • 36
  • 62

1 Answers1

5

The JCLDebug unit in the Jedi Code Library will allow you to get a stack trace that you can then pass on through CodeSite. Personally, I use madExcept which is much more flexible and well worth the tiny investment. This will allow you to log an entire bug report (including a stack trace) through Code Site.

Andy_D
  • 2,340
  • 16
  • 21
  • Thanks. But we had to remove all JCL and JEDI dependencies last month for an unrelated issue. I've read up on madExcept and it appears to be most highly recommended. – reckface Jul 07 '14 at 10:43