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

Exception trhown during Catching... How to get both exception Info?

Hello Everybody!

Considering this code:

try
{
ExecuteOperation();
}
catch
{
Rollback();
throw;
}

Now, if ExecuteOperation() throws an exception "exA", AND during catching
also Rallback() throws an Exception "exB", I will lose every information
about exA!

The only way I found for not losing info is something like:

try
{
ExecuteOperation();
}
catch (Exception exA)
{
try
{
Rollback();
throw exA;
}
catch (Exception exB)
{
throw new ComboException(exA.Message+" and
"+exB.Message,exA,exB);
}
}

....but I would like to know if there is a better way of doing it!

Thank you!
Paolo.
Jan 22 '07 #1
2 1454
Ever thought of writing the inner excpetion to an error log or the event
log? Then when the outer exception fires you have an inner exception to
grab? Also a second catch on ExB would catch that one as well i guess? but
only the one that fires first.


"Paolo" <pa***@paolo.comwrote in message
news:%2***************@TK2MSFTNGP05.phx.gbl...
Hello Everybody!

Considering this code:

try
{
ExecuteOperation();
}
catch
{
Rollback();
throw;
}

Now, if ExecuteOperation() throws an exception "exA", AND during catching
also Rallback() throws an Exception "exB", I will lose every information
about exA!

The only way I found for not losing info is something like:

try
{
ExecuteOperation();
}
catch (Exception exA)
{
try
{
Rollback();
throw exA;
}
catch (Exception exB)
{
throw new ComboException(exA.Message+" and
"+exB.Message,exA,exB);
}
}

...but I would like to know if there is a better way of doing it!

Thank you!
Paolo.


Jan 22 '07 #2
Ever thought of writing the inner excpetion to an error log or the event
log?
I think I'm following this suggestion...

Thank you,
Paolo.
Jan 23 '07 #3

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

Similar topics

10
by: Frank | last post by:
Using Python 2.2.2, I want to catch all exceptions from "socket.gethostbyaddr(ip)" From IDLE, I can generate: >>> socket.gethostbyaddr('1.2') Traceback (most recent call last): File...
42
by: cody | last post by:
public DateTime Value { get { try { return new DateTime(int.Parse(tbYear.Text), int.Parse(tbMonth.Text), int.Parse(tbDay.Text)); } catch (FormatException)
6
by: Páll Ólafsson | last post by:
Hi I have a problem with the Microsoft.ApplicationBlocks.ExceptionManagement? I can't get it to work in RELEASE mode? If I run the project in debug mode the block works fine but when I run the...
11
by: Master of C++ | last post by:
Hi, I am writing a simulation package in C++, and so far I've written about 8000 lines of code and have about 30 classes. I haven't used C++ exceptions so far (for various reasons). The only two...
2
by: frazer | last post by:
1 when i get an error in my code where the error is not handled, all i get is a system error, i dont get detailed information that i get when the code is in a try catch block. how do i get that...
11
by: chopsnsauce | last post by:
Here's the example: Dim frm As New FORM1 Try frm.show Catch ex As Exception msgbox ex.message
3
by: arasub | last post by:
ep 20, 2007 11:25:57 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found...
10
by: Rahul | last post by:
Hi Everyone, I have the following exception class, class E1 { }; class E2 {
35
by: eliben | last post by:
Python provides a quite good and feature-complete exception handling mechanism for its programmers. This is good. But exceptions, like any complex construct, are difficult to use correctly,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.