Unwinding is the act of cleaning up the stack. In addition to the Local Unwind, there is a Global Unwind. This occurs when there are nested functions and an exception takes place, and an Exception Filter further up the call stack is evaluated to EXCEPTION_EXECUTE_HANDLER, thus causing all the outstanding try-finally block between the exception and the exception handler to be executed.
The code execution sequence of a Global Unwind would be as follows:
/* Code before try block */ (1)
__try{
/* Guarded body */ (2)
/* Call another function */
function();
/* Code here is never executed */
}
__except( EXCEPTION_EXECUTE_HANDLER /* Exception Filter */ ){(6)
/* Exception handler only executes after the global unwind*/ (8)
}
/* Code after the exception handler */ (9)
void function(void) {
/* function code */ (3)
__try{
/* Guarded Body */ (4)
/* an exception occurs here */ (5)
}
__finally {
/* Global Unwind occurs to unwind all pending finally-blocks */(7)
}
/* Code here never executes */
}
Global Unwind can be halted by placing a return inside a finally block. Unwinding stops and execution continues as though nothing ever happened. The code inside the exception handler will not be executed even though the code inside the Exception Filter was executed. Usually, this technique should be avoided.
![]()
Structured Exception Handling
Exception Handler
Exception Handler - Exception
Information
Exception Handler -
RaiseException
Termination Handler - Local
Unwind
