Page 1 of 1

Stack trace in application.onexception

PostPosted: Fri Sep 21, 2018 11:33 am
Hello Madshi

Thank you for an excellent product! It works very well.

I would like to get stacktrace in Application.OnException for unhandled exceptions:

uses MadStackTrace;

procedure Tform1.AppException(Sender: TObject; E: Exception);
var s : string;
s := MadStackTrace.StackTrace(true);
// s = '' 15 TForm1.AppException'#$D#$A' ... initialization'
// had hoped to see:
// S= '' 22 Tform1.Button1Click ...'

It seems, that the stack is cleared prior to AppException is called?

I Know, I can make the madshisystem handle unhandled exceptions, but I would like to show the same error dialogue, that I use for handled exceptions (here I can get the correct stack dump)
How do I get the stack dump un unhandled exceptions?

Best regards
Thomas Riedel

Re: Stack trace in application.onexception

PostPosted: Tue Sep 25, 2018 8:43 am
by madshi
Hi Thomas,

Application.OnException is hooked by madExcept and should not even be called at all. I wonder why/how it's called for you!?? :o

Anyway, you can use madExcept.RegisterExceptionHandler() to be notified about unhandled exceptions. Please be careful with the parameters of that function. They define in which thread context your callback is called. If you want to show your own VCL dialog, you need to be aware of that the VCL is not thread safe. madExcept's own dialogs are all done without VCL, using pure win32 APIs, to make them perfectly thread safe.

Re: Stack trace in application.onexception

PostPosted: Wed Sep 26, 2018 6:50 am
It worked partially because Mad except was not linked into the application.
All threads in my system are inside try .. except, so the dialog does not need to be thread safe in this case.
Can you link to an example with registerexceptionhandler, where where I can see how to get the stack?

Best regards

Re: Stack trace in application.onexception

PostPosted: Wed Sep 26, 2018 8:38 am
by madshi
We're talking about unhandled exceptions, no? Those are handled by madExcept in a secondary thread, so your RegisterExceptionHandler() callback can also be called in the context of a secondary thread. But you can define in which thread context you want your callback to be called, so RegisterExceptionHandler() parameters.

There is a little sample code at the bottom of this page:

However, it runs in a secondary thread because it doesn't need VCL.