madExcept and indy threads

delphi package - automated exception handling
Post Reply
markh
Posts: 4
Joined: Mon Feb 21, 2005 3:51 pm

madExcept and indy threads

Post by markh »

Does madexcept work in Indy threads?

Mark
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Post 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.
markh
Posts: 4
Joined: Mon Feb 21, 2005 3:51 pm

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

Post 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.
markh
Posts: 4
Joined: Mon Feb 21, 2005 3:51 pm

Post by markh »

Thanks, it works perfect.

Mark
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

That's nice... :D
gambit47
Posts: 6
Joined: Wed May 31, 2006 8:02 pm

Re:

Post 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.
Post Reply