CJCoding With Joseph
15free / daySign inCreate account
Back to Multiple Choice Quiz

Select topics to narrow your question pool, then enable Random to jump to a random question matching your filters.

Topics

Catch by Value Causes Slicing

C++ quiz · Question 47
mediumExceptions

What is the output of this code?

Code

1#include <iostream>
2#include <stdexcept>
3using namespace std;
4 
5class MyError : public runtime_error {
6public:
7 MyError() : runtime_error("base message") {}
8 const char* what() const noexcept override {
9 return "derived message";
10 }
11};
12 
13int main() {
14 try {
15 throw MyError();
16 } catch (runtime_error e) { // catch by VALUE
17 cout << e.what() << endl;
18 }
19 return 0;
20}