473,412 Members | 4,957 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 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 1435

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: OvErboRed | last post by:
I just read a whole bunch of threads on microsoft.public.dotnet.* regarding checked exceptions (the longest-running of which seems to be <cJQQ9.4419 $j94.834878@news02.tsnz.net>. My personal...
4
by: Laxmikant Rashinkar | last post by:
Hi, I am working with a program that someone else wrote. This program is full of bugs and unhandled exceptions are thrown all over the code. Instead of trying to catch the exception at each...
5
by: Ron James | last post by:
In my multi-threaded application, a Win32 structured exception is occasionally thrown from a worker thread. Or perhaps a worker thread might throw a C++ exception. I can catch the Win32...
7
by: cmay | last post by:
FxCop complains every time I catch System.Exception. I don't see the value in trying to catch every possible exception type (or even figuring out what exceptions can be caught) by a given block...
12
by: Vasco Lohrenscheit | last post by:
Hi, I have a Problem with unmanaged exception. In the debug build it works fine to catch unmanaged c++ exceptions from other dlls with //managed code: try { //the form loads unmanaged dlls...
0
by: Wild Wind | last post by:
Hello, I have a mixed dll which has to catch standard c++ library exceptions. Now I understand that when *any* object is thrown as an exception in managed c++, it is wrapped as a SEHException...
0
by: Epetruk | last post by:
Hello, I posted this a while back, but I have had no response yet. I have a mixed dll which has to catch standard c++ library exceptions. Now I understand that when any object is thrown as...
3
by: Mike Binks | last post by:
I wish to make sure all unhandled exceptions (UE) are handled by a central handler. For primary thread UEs, this may be done by string exceptionText; ...
5
by: Simon Tamman | last post by:
I have an object named DisasterRecovery. The Ctor of this object is this: private DisasterRecovery() { Application.ThreadException+= new...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
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...

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.