If I have a code like the following:
try {
doSomething();
} catch (...) {
noteError();
}
void noteError() {
try {
throw;
} catch (std::exception &err) {
std::cerr << "Note known error here: " << err.what();
} catch (...) {
std::cerr << "Note unknown error here.";
}
throw;
}
Will the original exceptions get thrown from both places inside the lower frame of noteError()?
The wording in the standard (§15.1/2) is (emphasis mine):
When has a try block "exited"? According to the grammar (§15/1), try blocks end with a sequence of handlers, so the block ends when the last handler ends. In other words:
So yes, your code is fine. When re-thrown, the nearest try block has a matching handler (namely
catch (...)
), so that handler is entered.