Practice mode C++

What happens if an exception escapes from a function declared noexcept?

Correct answer B. std::terminate is called

Explanation

noexcept is a promise that the function will not throw. If an exception does try to leave it, the runtime calls std::terminate instead of propagating it further, and stack unwinding may not happen. Because callers rely on the promise, for example std::vector moves elements only through noexcept move constructors, the guarantee must be kept carefully.

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.