Skip to content
Quiz · Exceptions · lesson 7 of 7

Quiz — an exception in a destructor

What happens when this program runs?

C++
#include <iostream>
#include <stdexcept>

struct Logger {
    ~Logger() { throw std::runtime_error("flush failed"); }
};

int main() {
    try { Logger log; }
    catch (const std::exception&) { std::cout << "caught"; }
}