Stack trace in application.onexception

delphi package - automated exception handling

Stack trace in application.onexception

Postby tr@logihouse.dk » 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;
begin
s := MadStackTrace.StackTrace(true);
// s = '' 15 TForm1.AppException'#$D#$A' ... initialization'
// had hoped to see:
// S= '' 22 Tform1.Button1Click ...'
end;

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
tr@logihouse.dk
 
Posts: 2
Joined: Fri Sep 21, 2018 11:15 am

Re: Stack trace in application.onexception

Postby madshi » Tue Sep 25, 2018 8:43 am

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.
madshi
Site Admin
 
Posts: 9810
Joined: Sun Mar 21, 2004 5:25 pm

Re: Stack trace in application.onexception

Postby tr@logihouse.dk » 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
Thomas
tr@logihouse.dk
 
Posts: 2
Joined: Fri Sep 21, 2018 11:15 am

Re: Stack trace in application.onexception

Postby madshi » Wed Sep 26, 2018 8:38 am

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:

http://help.madshi.net/HowToUseMadExcept.htm

However, it runs in a secondary thread because it doesn't need VCL.
madshi
Site Admin
 
Posts: 9810
Joined: Sun Mar 21, 2004 5:25 pm


Return to madExcept

Who is online

Users browsing this forum: No registered users and 6 guests