How are exceptions allocated on the stack caught beyond their scope?
- by John Doe
In the following code, the stack-based variable 'ex' is thrown and caught in a function beyond the scope in which ex was declared. This seems a bit strange to me, since (AFAIK) stack-based variables cannot be used outside the scope in which they were declared (the stack is unwound).
void f() {
SomeKindOfException ex(...);
throw ex;
}
void…