Throughout the function handleException, the exception encountered is implicit. How does the compiler handle such implicit passing of exceptions? [For e.g. in C++ methods, this pointer is passed to account for the current object. My question is how does a compiler handle exceptions internally - handleException has no arguments.]
void handleException()
{
try {
throw;
}
catch (MyException& e) {
...code to handle MyException...
}
catch (YourException& e) {
...code to handle YourException...
}
}
void f()
{
try {
...something that might throw...
}
catch (...) {
handleException();
}
}
1 Answer 1
Pay no attention to that man behind the curtain.
Because the compiler knows how it implements exceptions, it can use that internal information. The simplest way is to use a global (or thread local) variable to store info about any "active" exception; then retrieve that, mostly to get type info, and propagate. C++0x partially exposes this information with std::exception_ptr; see §18.8.5 in N3225.
Exceptions are handled differently from parameters; analogy to "this" won't be helpful. The value for "this" is usually treated as a normal pointer parameter, except for being hidden from the user behind the curtain.
throw;
statement? If it is not mentioned, is that not implicit? It sounds like you are forming an opinion based on the title alone without actually reading the question body, which explicitly mentions what the OP means by "implicit" (which is also not a term used in the standard).