Why doesn\'t the following doesn\'t handle the exception that was rethrown? I tried all the combinations but none of them would show the output in last catch so I\'m confused!>
The re-throw is not handled by the same try-catch
block. It's thrown up to the calling scope.
In [except.throw]
(2003 wording):
A throw-expression with no operand rethrows the exception being handled.
and:
When an exception is thrown, control is transferred to the nearest handler with a matching type (15.3); “nearest” means the handler for which the compound-statement, ctor-initializer, or function-body following the try keyword was most recently entered by the thread of control and not yet exited.
Your try
block has exited, so its handlers are not candidates. Thus, none of the catch
blocks in your code may handle the re-throw.
Admittedly this is rather confusing wording.