← Back to Question List
C++ Quiz #49
Exception Thrown in Constructor
What is the output of this code?
📄 Code
1#include <iostream>2#include <stdexcept>3using namespace std;45class Config {6public:7 Config(int value) {8 if (value < 0) {9 throw invalid_argument("Negative value");10 }11 cout << "Config created: " << value << endl;12 }13};1415int main() {16 try {17 Config c1(10);18 Config c2(-1);19 Config c3(20);20 } catch (const invalid_argument& e) {21 cout << e.what() << endl;22 }23 return 0;24}