Consider the following simple C++ code:
void foo() {
throw(my_exception());
}
void check_exc(const my_exception &exc) {
/* Do stuff with exc */
}
void bar() {
try {
foo();
} catch(const my_exception &exc) {
check_exc(exc);
}
}
In bar
's exception handler, how comes the exception referenced by exc
is still alive, seeing as how it was allocated in foo
's stack frame? Shouldn't that frame have been unwound by the time the exception handler gets to run, and any values allocated there already be considered dead? Especially so since I'm explicitly calling another function which would need that stack space.
As a C programmer trying to learn C++, what am I misunderstanding here? Where do these various values actually exist in memory, more precisely?