Can't throw exception in calling class.

  • Thread starter Thread starter benjamin.soulier
  • Start date Start date
B

benjamin.soulier

Hello all,

I got a problem using Exceptions in Debug mode in Visual Studio :
I got an Exception on a classe like :

catch Exception(e)
{
DoSomething();
throw e;
}

Running in debug mode when getting this exception works fine, but
trying to continue running code intercepting this exception in calling
classes doesn't work ; it's coming coming back over and over again on
this exception (no way to intercept it upper class methods).

Do you have any clue ?

Thanks everyone
 
I got a problem using Exceptions in Debug mode in Visual Studio : I
got an Exception on a classe like :

catch Exception(e)
{
DoSomething();
throw e;
}
Running in debug mode when getting this exception works fine, but
trying to continue running code intercepting this exception in calling
classes doesn't work ; it's coming coming back over and over again on
this exception (no way to intercept it upper class methods).

Typically you would wrap the exception in a custom exception and throw the
new wrapped version as follows:

catch Exception(e)
{
DoSomething();
throw new MyCustomInheritedException(e);
}

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
 
Back
Top