You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Exceptions use these inheritance relationships to determine whether a handler catches an exception. Handlers will catch a given type and any of its parents' types.
The bold sentence above says the opposite of the truth. In reality, handlers catch a given type and any of its children's types. This is a very important difference. Newbies will be confused.
The following function can be called to prove that it is the children's types that are caught:
#include <stdexcept>
void test_exception_hierarchy_catch() {
try {
throw std::exception("This exception is an instance of std::exception.\n");
}
catch (const std::runtime_error& ex) {
printf("Caught an std::runtime_error.\nThe message is: %s\n", ex.what());
}
catch (const std::exception& ex) {
printf("Caught an std::exception.\nThe message is: %s\n", ex.what());
}
}
The text was updated successfully, but these errors were encountered:
In the following text:
The bold sentence above says the opposite of the truth. In reality, handlers catch a given type and any of its children's types. This is a very important difference. Newbies will be confused.
The following function can be called to prove that it is the children's types that are caught:
The text was updated successfully, but these errors were encountered: