Click to See Complete Forum and Search --> : Handling Exceptions Across Threads


grahamr (work)
June 7th, 2007, 05:30 AM
I am writing a program that handles data connections across a wireless connection. The environment is quite noisy so I need to handle disconnections.

The current method is that a user clicks a "job" button which causes a modal dialog to open. This dialog connects to the remote host and tries to download a new task. When the new task is downloaded the dialog closes and the user can now do other stuff related to the job.

When an 'unclean' disconnection happens (not terminated by the correct disconnect code) the program fires an exception. However the exception is triggered in another thread which propagates down to the run() function. From here the code disappears back into the kernal. The main program (the dialog) doesn't know there is a disconnection.

I was wondering if anyone else has done similar and what strategies I could employ that the main application can handle temporary and permanent outages?

Thanks, Graham Reeds

Arjay
June 7th, 2007, 11:58 AM
What you can do is capture the exception in your secondary thread, cleanup and post a message to the primary thread indicating that it needs to cleanup as appropriate.

vijay96238
June 8th, 2007, 01:13 AM
Each thread can handle its own exception list.
i.e. The thread, that is doing network communication should catch all exception related to network problem.
And, then, it can use shared variable to pass message to other thread to do windup job.

I guess, sometime, signal would not arrive to the thread -- that you were expecting, that depends on the system functions you have used in both threads & underlaying architecture. If signal arrive to other thread due to this, you need to have same shared variable to pass message to all other threads.

What i did at one place, is the thread which handles socket connection, always check after regular time interval for Error of other threads (i.e. bool thread1Error).

Vijay.

grahamr (work)
June 8th, 2007, 09:27 AM
What you can do is capture the exception in your secondary thread, cleanup and post a message to the primary thread indicating that it needs to cleanup as appropriate.

Would you say to use PostMessage or PostThreadMessage as the way to communicate back that an error has occurred?

Thanks, G.

Arjay
June 8th, 2007, 12:38 PM
Would you say to use PostMessage or PostThreadMessage as the way to communicate back that an error has occurred?

Thanks, G.I'd use a user defined msg and PostMessage and pass some small amount of data in a struct as to what the UI needs to clean up.