Quiz · Exceptions · lesson 4 of 7
Quiz — catch by value
What does the program print?
#include <iostream>
struct Error {
virtual int code() const { return 1; }
};
struct NotFound : public Error {
int code() const override { return 404; }
};
int main() {
try { throw NotFound{}; } catch (Error e) { std::cout << e.code() << ' '; }
try { throw NotFound{}; } catch (const Error& e) { std::cout << e.code(); }
}