Catch the "Frozen main thread"

delphi package - automated exception handling
Post Reply
magnomp
Posts: 10
Joined: Wed May 02, 2007 5:24 pm

Catch the "Frozen main thread"

Post by magnomp »

Is it possible to catch the error generated by madExcept when the main thread was frozen?
I want to catch this error and handle it by myself.
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Sure, just use "RegisterExceptionHandler". In your exception handler you can then do: "if exceptIntf.ExceptType = etFrozen then".
magnomp
Posts: 10
Joined: Wed May 02, 2007 5:24 pm

Post by magnomp »

This can be done in TMadExceptionHandler.OnException?
Acording to this page, that component encapsulates the RegisterExceptionHandler for me. But my OnException event handler isn't called when madExcept generates the frozen error.
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

"TMadExceptionHandler.OnException" does encapsulate RegisterExceptionHandler. However, RegisterExceptionHandler has a number of parameters. And TMadExceptionHandler.OnException sets them so that things are VCL compatible. That means "stTrySyncCallOnSuccess" is used. If a "frozen" situation occurs, syncing doesn't work, as a result "TMadException.OnException" isn't called.

You need to call RegisterExceptionHandler manually and use "stDontSync". This way you will be called for "frozen" exceptions, too. However, your handler will be called in the context of a secondary thread, so you're not allowed to do VCL stuff in there. You may want to continue using "TMadExceptionHandler.OnException" for normal exceptions, if you need your handler to be called in the context of the main thread. You can use "stDontSync" only for handling "frozen" exceptions, if you want. You can register as many exception handlers with different or same settings as you want.
Post Reply