I have a class whose constructor may throw an exception. Here’s some code that will catch the exception:
try { MyClass instance(3, 4, 5); } catch (MyClas
Dynamically allocate the instance using new:
new
std::unique_ptr instance; try { instance.reset(new MyClass(3, 4, 5)); } catch (const MyClassException& ex) { std::cerr << "There was an error creating the MyClass." << std::endl; return 1; } // use instance as needed...