Exception Handling & Error Management Flashcards
7 cards from real CPP practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Exception Handling & Error Management flashcards as text
What is the basic exception guarantee?
Answer: If an exception is thrown, no resources are leaked and objects remain in a valid (but unspecified) state
The basic guarantee promises no resource leaks and that all objects remain in some valid state, but does not guarantee rollback of state changes.
What does std::make_exception_ptr(e) do?
Answer: Creates an std::exception_ptr holding a copy of e without throwing
std::make_exception_ptr() creates an std::exception_ptr from an exception value without needing an active exception or a throw.
Which statement about exception specifications in C++17 and later is correct?
Answer: noexcept(false) and noexcept(true) are the only valid exception specifications
C++17 removed dynamic exception specifications; only noexcept (equivalent to noexcept(true)) and noexcept(false) remain valid.
When catching multiple exception types, what rule determines which catch block is selected?
Answer: The first catch block whose type matches (including base-class matches) is selected
Catch handlers are checked in textual order; the first handler whose type matches (by identity or public base class) is executed.
What is the result of calling std::abort() compared to throwing an unhandled exception?
Answer: std::abort() terminates immediately without stack unwinding; an unhandled exception calls std::terminate()
std::abort() terminates immediately without calling destructors or atexit handlers; an unhandled exception calls std::terminate() which by default calls abort().
What is the purpose of nested exceptions (std::nested_exception)?
Answer: Chaining a new exception to a currently active one to preserve context
std::nested_exception allows catching an exception, then throwing a new one that embeds the original, preserving the full exception chain.
Which of the following best describes exception-neutral code?
Answer: Code that allows exceptions from called functions to propagate unchanged to the caller
Exception-neutral code neither swallows nor transforms exceptions from functions it calls, allowing them to propagate to the caller transparently.