Practice mode C++

What happens when a C++ exception is thrown and no matching catch handler is found anywhere up the call stack?

Correct answer B. std::terminate is called, which by default aborts the program

Explanation

If no handler matches, the runtime calls std::terminate, whose default action is std::abort. Whether the stack is unwound before that is implementation-defined, so destructors may not run. That is why programs often wrap main's body in a try block with catch (const std::exception&) to report the error and clean up gracefully.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.