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

P

Paolo

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.
 
D

Daniel

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top