fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. class LoggingLibrary
  5. {
  6. public:
  7. LoggingLibrary(int trigger=0) // for demonstration purposes
  8. {
  9. if ( trigger > 0)
  10. throw "Error";
  11. }
  12. };
  13.  
  14. using namespace std;
  15.  
  16. int main()
  17. {
  18. unique_ptr<LoggingLibrary> logLib;
  19. try
  20. {
  21. logLib = make_unique<LoggingLibrary>(1);
  22. }
  23. catch(const char *msg)
  24. {
  25. cout << "Didn't initialize";
  26. }
  27. if ( logLib )
  28. {
  29. cout << "Hey I'm ok"; // no exception thrown
  30. }
  31. }
  32.  
  33.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Didn't initialize