Notes on ExceptionChainPausingEx and ExceptionChainReplacingEx examples ----------------------------------------------------------------------- What we know: + entering "catch" block "pauses" the currently propagated exception + entering "finally" block "pauses" the currently propagated exception What happens if new exception is thrown in "catch" or "finally" block? + it normally propagates + if there is a nested "catch" or "finally" block in the original catch/finally, pausing the new exception by the nested block does NOT replace the original exception, but new paused exception is pushed on top of a stack of paused exceptions, that CLR manages For every "finally" block: + if NO exception propagates out of the "finally" block, the exception paused by it is unpaused and continues its propagation (and is removed from top of the paused exception stack) + if new exception propagates out of the "finally" block, then it replaces the exception "paused" by that "finally" block - the "paused" exception is removed from top of the paused stack, and its propagation is cancelled - ONLY the new exception propagates For every "catch" block: + if NO exception propagates out of the "catch" block, the exception paused by it is handled (and is removed from top of the paused exception stack) and its propagation is cancelled + if NO exception propagates out of the "catch" block + the "paused" exception is rethrown via "throw;", the rethrown exception is unpaused and continues its propagation (and is removed from top of the paused exception stack) + if new exception propagates out of the "catch" block then it replaces the exception "paused" by that "catch" block - the "paused" exception is removed from top of the paused stack, and its propagation is cancelled - ONLY the new exception propagates The ExceptionChainPausingEx and ExceptionChainReplacingEx show this on "finally" example.