473,471 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Execption handling for Thread

Hi:

I will appreciate your comment on the followings:

From the main program I start threads. After starting the thread the main
program do some other processing. If any of the threads throws any error
during their processing, I want to capture that exception from host and log
it.

Is it possible to capture the exception that a thread throws from the main
program?

Thanks

Jul 21 '05 #1
3 1415
pothik05 <po******@discussions.microsoft.com> wrote:
I will appreciate your comment on the followings:

From the main program I start threads. After starting the thread the main
program do some other processing. If any of the threads throws any error
during their processing, I want to capture that exception from host and log
it.

Is it possible to capture the exception that a thread throws from the main
program?


Have a look at AppDomain.UnhandledException. Of course, if you control
the other threads yourself, you could make the top-level method that
the thread starts with have a big try/catch which can feed the
exception back to the main thread (or log it, or whatever).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Hi Jon

Thanks for your reply. I can have a big try/catch in the method that starts
the thread and log the exception. But how will I "feed the exception back to
the main thread"? I can raise an event to notify the main program, but is
there any other way to catch any unhandled exception of the thread from the
main program.

"Jon Skeet [C# MVP]" wrote:
pothik05 <po******@discussions.microsoft.com> wrote:
I will appreciate your comment on the followings:

From the main program I start threads. After starting the thread the main
program do some other processing. If any of the threads throws any error
during their processing, I want to capture that exception from host and log
it.

Is it possible to capture the exception that a thread throws from the main
program?


Have a look at AppDomain.UnhandledException. Of course, if you control
the other threads yourself, you could make the top-level method that
the thread starts with have a big try/catch which can feed the
exception back to the main thread (or log it, or whatever).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #3
pothik05 <po******@discussions.microsoft.com> wrote:
Thanks for your reply. I can have a big try/catch in the method that starts
the thread and log the exception. But how will I "feed the exception back to
the main thread"? I can raise an event to notify the main program, but is
there any other way to catch any unhandled exception of the thread from the
main program.


No, you can't *catch* the exception in a different thread, but I'm not
sure why you'd want to, if all you need to do is log it.

To tell the main thread about the exception, just do the same as you
would for anything else which needs to get back to the UI thread - use
Control.Invoke or Control.BeginInvoke.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: A. Saksena | last post by:
Hi, Do anybody have an idea of the performance penalty while using exception handling (specially with g++) Abhishek
34
by: rawCoder | last post by:
I have read that Exception Handling is expensive performance wise ( other than Throw ) , but exactly how ? Please consider the following example ... ////////////////// Code Block 1...
5
by: pothik05 | last post by:
Hi: I will appreciate your comment on the followings: From the main program I start threads. After starting the thread the main program do some other processing. If any of the threads throws...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.