← Back to Question List
C++ Quiz #47
Catch by Value Causes Slicing
What is the output of this code?
📄 Code
1#include <iostream>2#include <stdexcept>3using namespace std;45class MyError : public runtime_error {6public:7 MyError() : runtime_error("base message") {}8 const char* what() const noexcept override {9 return "derived message";10 }11};1213int main() {14 try {15 throw MyError();16 } catch (runtime_error e) { // catch by VALUE17 cout << e.what() << endl;18 }19 return 0;20}