Thursday, November 25, 2010

Rethrowing Exceptions

When catching an exception e, is it better to rethrow the exception with 'throw;' rather than 'throw e;', because 'throw e' may throw away information if the exception was caught with a super class type. If the exception is caught by value, rethrowing the exception using the name of the exception will slice off any extra data, if the exception object is has a dynamic type more derived than the type in the catch specification. If the exception is caught by reference (using a reference (&) or pointer(*)), rethrowing the exception will not slice off the information. For the most part, it is better to re-throw without the variable name.


No comments:

Post a Comment