473,399 Members | 3,302 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,399 software developers and data experts.

Throwing an exception on a thread....

Hi,

I have 2 menu items on the Debug menu of my application:

Throw Exception On Form and
Throw Exception In Worker Thread

The former just executes:

throw new Exception ( "I'm testing exception handling here" )

but I want the second to make my worker thread throw an exception too. I
thought about using Thread.Abort to make it throw a thread abort exception,
but I would rather somehow raise the exception on the thread in a more
general way (i.e. a general exception, or an exception type of my choosing).
As the worker thread performs one of a hundred or so different operations, I
don't want to have to insert "throw now" logic into every single operation
and, moreover, this will make the exception throw at the same place each
time, not good for testing.

So, in short, is it possible to throw an exception from one thread to be
handled on another?


Nov 17 '06 #1
2 1601
>So, in short, is it possible to throw an exception from one thread to be
>handled on another?
Not just like that. You have to use some kind of thread
synchronization machanism, such as a ManualResetEvent, to signal the
the thread to execute the code you want.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '06 #2
Not just like that. You have to use some kind of thread
synchronization machanism, such as a ManualResetEvent, to signal the
the thread to execute the code you want.
Okay, I thought that might be the case. Thanks anyway.
Nov 18 '06 #3

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

Similar topics

1
by: Farooq Khan | last post by:
i'm writing a class library having following code snippet. i want this class to report an error (by throwing an Exception) to the application using this class library. the problem is that within...
40
by: Kevin Yu | last post by:
is it a bad programming design to throw exception in the try block then catch it??
4
by: Terry | last post by:
Hello, I am trying to get a response for an .aspx page in my current project (same virtual directory) by using WebRequest.GetResponse but I keep getting a exception with "500 Internal server...
4
by: ajfish | last post by:
Hi, I would like to re-throw an exception but keep the stack trace from when the exception was originally generated. Is there any way of doing this (using .Net 1.1)? I am not throwing it from...
15
by: Sek | last post by:
Gurus, I am wondering whether it is right to throw an exception from a Property of an object. To get into it further, is it okay to throw exception during 'get' operation? I was searching...
4
by: bhc | last post by:
all- up until just recently, i was fairly sure i'd implemented a RasDial class in VB.NET complete with a callback to get updated status. from this wrapper, when i throw an event back to the...
1
by: usenet | last post by:
I wrote some sample code (see below) for nested exception throwing i.e. my catch blocks are throwing exceptions of their own (for simplicity I used standard exceptions). I am getting some...
4
by: Arnie | last post by:
Folks, The GZipStream class in .NET is throwing an exception during an OS unseal/power up (first boot experience). The .NET system is fully up as other apps seem to run fine.
9
by: thagor2008 | last post by:
Is the behaviour of throwing exceptions in a unix signal handler defined? eg: void sighandler(int sig) { ... do something throw myobj; }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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,...

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.