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

  • Thread starter Thread starter Paolo
  • Start date Start date
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.
 
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.
 
Back
Top