TurboPack / AsyncPro

Async Professional is a comprehensive communications toolkit for Embarcadero Delphi and C++Builder.
101 stars 50 forks source link

ShowException handler #24

Closed mrcsms closed 2 years ago

mrcsms commented 2 years ago

Hi, this is my small modification which allows handling critical exceptions in, for example, multithreaded applications (my case). Accepting PR would make my life easier :). greetings

mrcsms commented 2 years ago

thanks, but your second commit change behavior, what makes you prefer to write it that way (I'm curious and I will maybe learn something)... sometimes I used it like: initialization AwUser.GShowExceptionHandler := nil; and it won't work now. of course, I will change it to assign an empty method here and it's not a problem at all.

romankassebaum commented 2 years ago

And what exactly does not work? The exception handler is initialized with nil

{code} var GShowExceptionHandler: procedure(ExceptObject: TObject; ExceptAddr: Pointer) = nil; {code}

and in case of an exception the normal handler is called if the global one is nil, otherwise the global is called.

{code} except // SWB on E : Exception do // SWB begin // SWB if Assigned(GShowExceptionHandler) then GShowExceptionHandler(E, ExceptAddr) else ShowException(ExceptObject, ExceptAddr); end; // SWB {code}

In your solution the global could be set to nil and then there is no handler any longer.

romankassebaum commented 2 years ago

Or do mean the ExceptObject instead of E? This was a copy paste not-modify issue. I fixed it.

mrcsms commented 2 years ago

no, no, it's initialized with the origin SysUtils.ShowException - see InitializeUnit GShowExceptionHandler := SysUtils.ShowException;

romankassebaum commented 2 years ago

But you can always write

GShowExceptionHandler := nil;