473,547 Members | 2,532 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1613
>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 ManualResetEven t, 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 ManualResetEven t, 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
1650
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 that try block there are several exceptions that this class itself needs to handle (interrnally). now when the exception, UserAlreadyRegistered, is...
40
13474
by: Kevin Yu | last post by:
is it a bad programming design to throw exception in the try block then catch it??
4
7219
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 error" in the exception message. I am able to do this fine with another .aspx page that has no code-behind. The page that has code-behind throws the...
4
1523
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 the same place it was caught (in fact it is caught in a worker thread which squirrels it away and then the main thread digs it out later and throws...
15
3232
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 for MS articles on throwing exceptions. But, in vain.
4
3782
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 calling program, i can console.writeline the state successfully. but as soon as i replace that line with updating the UI, the program freezes, and...
1
3257
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 extraneous characters (St9) in my final output. Can anyone kindly help me interpret that please? Thanks, Ramesh
4
3448
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
5798
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
7703
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7797
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5362
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5081
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3493
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3473
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1923
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1050
muto222
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.