473,394 Members | 2,031 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,394 software developers and data experts.

Rethrowing exceptions

I am implementing an asynchronous handler (similar to Control.EndInvoke) and
if the other thread throws an exception, I catch it and rethrow it on the
current thread. How can I rethrow the exception on the current thread while
maintaining the stack trace? The best I've come up with is encapsulating
the exception as an inner exception. I would prefer to just rethrow the
exception directly -- no need for an inner exception.

How does Control.EndInvoke handle this?

Thanks
May 6 '07 #1
4 2355
"Coder Guy" <Co******@discussions.microsoft.comwrote in message
news:ul**************@TK2MSFTNGP06.phx.gbl...
>I am implementing an asynchronous handler (similar to Control.EndInvoke)
and if the other thread throws an exception, I catch it and rethrow it on
the current thread. How can I rethrow the exception on the current thread
while maintaining the stack trace? The best I've come up with is
encapsulating the exception as an inner exception. I would prefer to just
rethrow the exception directly -- no need for an inner exception.
You can rethrow the current exception writing just "throw;" instead of
"throw myNewException;".
May 7 '07 #2
I think you missed the point. The exception is saved and rethrown on
another thread, and therefore, that won't work for me...
You can rethrow the current exception writing just "throw;" instead of
"throw myNewException;".

May 7 '07 #3
Once you "throw ex" rather than "throw" you lose the stack trace. So,
providing the innerException as you described is probably the only way to do
what you want, unless you want to copy everything to a new exception object.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Coder Guy" wrote:
I think you missed the point. The exception is saved and rethrown on
another thread, and therefore, that won't work for me...
You can rethrow the current exception writing just "throw;" instead of
"throw myNewException;".


May 7 '07 #4
Coder Guy <Co******@discussions.microsoft.comwrote:
I am implementing an asynchronous handler (similar to Control.EndInvoke) and
if the other thread throws an exception, I catch it and rethrow it on the
current thread. How can I rethrow the exception on the current thread while
maintaining the stack trace? The best I've come up with is encapsulating
the exception as an inner exception. I would prefer to just rethrow the
exception directly -- no need for an inner exception.

How does Control.EndInvoke handle this?
Are you sure that Control.EndInvoke *does* handle this? Does it appear
to replace the stack trace with the original one?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 8 '07 #5

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

Similar topics

16
by: David Turner | last post by:
Hi all I noticed something interesting while testing some RAII concepts ported from C++ in Python. I haven't managed to find any information about it on the web, hence this post. The problem...
21
by: dkcpub | last post by:
I'm very new to Python, but I couldn't find anything in the docs or faq about this. And I fished around in the IDLE menus but didn't see anything. Is there a tool that can determine all the...
2
by: Martin Smith | last post by:
If a class has no need for any specific clean up code in a particular catch block is there any benefit to catching and rethrowing exceptions, rather than just letting the original exception bubble up...
6
by: Chris Newcombe | last post by:
Please could someone on the VC++ 7.0 compiler team (note; not 7.1) tell me if this code is handled 'correctly' (i.e. as the original poster suggests) in all cases? ...
2
by: Lasse Vågsæther Karlsen | last post by:
If I got the following code: try { // something that might throw an exception } catch (Exception ex) { // Log contents of ex here throw;
5
by: Steven T. Hatton | last post by:
I haven't thought about rethrowing an exception in a long time, and tried to do it the wrong way. Now I'm curious about /why/ it's wrong. My expectation was that the exception instance would...
15
by: =?Utf-8?B?TWljaGVsIFBvc3NldGggW01DUF0=?= | last post by:
In my opinion rethrowing exceptions without providing anny extra information is a totall waste Examples : in my opinion wrong : A: Public sub DoSomeStuff() Try do it
13
by: valentin tihomirov | last post by:
I do not understand something. A caught exception stack points to an argument-free 'throw' in a catch block. Meantime, it is widely known that these statements re-throw the original exceptions. I...
5
by: jerseycat10 | last post by:
I am trying to overcome the following hurdle. We have several exception types, derived from a "BaseException" type. Lets say SpecialException inherits from BaseException. Lets say a...
0
RedSon
by: RedSon | last post by:
Chapter 3: What are the most common Exceptions and what do they mean? As we saw in the last chapter, there isn't only the standard Exception, but you also get special exceptions like...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.