views:

72

answers:

1

It is possible to catch an exception and throw a new exception which wraps the first exception as an inner exception:

http://msdn.microsoft.com/en-us/library/system.exception.innerexception(VS.71).aspx

Also, if I call a function and it throws a certain error, but I catch it, will the calling code's catch handler execute? If so, and it is of a higher exception type, is this not wrapping the exception?

eg I can throw exception ex of type IndexOutOfRange, log it but rethrow, catch a higher up exception and do something, or I can throw a new exception and wrap an inner exception like:

throw new MyException("some error", ex.InnerException)

Thanks

+1  A: 
  1. Yes you can throw an Exception that wraps the first Function

  2. Also, if I call a function and it throws a certain error, but I catch it, will the calling code's catch handler execute?

No.

  1. If so, and it is of a higher exception type, is this not wrapping the exception? I didnt quite get this one but it looks like the term Wrapper in its original sense.
Geek