471,627 Members | 1,213 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 software developers and data experts.

Catching exceptions thrown from threads?

Hi

Is it possible to catch exceptions thrown by a System.Threading.Thread
object?

i.e. I have an instance of a class that is created using the normal
Thread/ThreadStart method, but once it starts, there will be no try/catch
block to catch any exceptions thrown (other than the ones that might be
raised by the Thread/ThreadStart classes when I'm initiating the thread).

I was thinking of using events (i.e. instead of throwing an exception my
class can raise an event), but that still won't ensure all exceptions are
trapped.

Thanks
Alex
Feb 22 '06 #1
2 1381

"Alex" <no****@hotmail.com> wrote in message
news:43**********************@news.zen.co.uk...
Hi

Is it possible to catch exceptions thrown by a System.Threading.Thread
object?


If you are using Windows Forms you should be able to hook
Application.ThreadException event to handle unhandled exceptions thrown from
threads.
Feb 22 '06 #2
Put a try/catch around your whole thread start method. Then log or report
exception back to where ever as needed using event or your own queue.

--
William Stacey [MVP]

"Alex" <no****@hotmail.com> wrote in message
news:43**********************@news.zen.co.uk...
| Hi
|
| Is it possible to catch exceptions thrown by a System.Threading.Thread
| object?
|
| i.e. I have an instance of a class that is created using the normal
| Thread/ThreadStart method, but once it starts, there will be no try/catch
| block to catch any exceptions thrown (other than the ones that might be
| raised by the Thread/ThreadStart classes when I'm initiating the thread).
|
| I was thinking of using events (i.e. instead of throwing an exception my
| class can raise an event), but that still won't ensure all exceptions are
| trapped.
|
| Thanks
| Alex
|
|
Feb 22 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

26 posts views Thread by OvErboRed | last post: by
4 posts views Thread by Laxmikant Rashinkar | last post: by
5 posts views Thread by Ron James | last post: by
7 posts views Thread by cmay | last post: by
5 posts views Thread by Simon Tamman | last post: by
1 post views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.