Page 1 of 1

madExcept and indy threads

Posted: Mon Feb 21, 2005 3:59 pm
by markh
Does madexcept work in Indy threads?

Mark

Posted: Tue Feb 22, 2005 8:18 am
by madshi
I've not worked with Indy threads yet, so I'm not sure. It depends on whether the Indy threads manually catch exceptions or whether they leave the exception handling to Delphi's default. In the first case madExcept might not automatically take over the exception handling. In the latter case it will automatically catch&handle the exceptions. In the first case: Can you ask the Indy threads to notify you about exceptions? Then you can make it work quite easily.

Posted: Tue Feb 22, 2005 1:31 pm
by markh
MadExcept does not work in the indy threads of my application (it does work in my own thread classes that are derived from TThread). However the TidThread (indy thread) is a derived class of TThread the indy threads probably catches itself the exception.

I do not know what you exactly mean with notify but the indy thread has an onException event. Can I use that by retrieving the exception call stack?

BTW, I use Borland C++ Builder 6

Thanks,

Mark

Posted: Tue Feb 22, 2005 2:30 pm
by madshi
markh wrote:the indy thread has an onException event. Can I use that by retrieving the exception call stack?
Yes!

Please use that event and in there call: "madExcept.HandleException". That should work.

Posted: Tue Feb 22, 2005 3:00 pm
by markh
Thanks, it works perfect.

Mark

Posted: Tue Feb 22, 2005 3:24 pm
by madshi
That's nice... :D

Re:

Posted: Tue Mar 01, 2022 10:23 pm
by gambit47
madshi wrote: Tue Feb 22, 2005 8:18 am It depends on whether the Indy threads manually catch exceptions or whether they leave the exception handling to Delphi's default.
I know this is an old discussion. I'm just adding this for future reference.

Indy's TIdThread class does indeed have a try..except in its overridden Execute() method to catch all exceptions. It does not let Delphi's default mechanism handle them.

TIdThread passes the caught Exception to TIdThread.DoException(), which is virtual.

The base TIdThread.DoException() fires the TIdThread.OnException event. The wrapper TIdThreadComponent uses this to fire its own OnException event.

A derived class, TIdThreadWithTask, is used by TIdTCPServer, overriding TIdThread.DoException() to fire the TIdTCPServer.OnException event.