fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. struct A
  5. {
  6.  
  7. };
  8.  
  9. struct B
  10. {
  11. B() { throw std::runtime_error(""); }
  12. };
  13.  
  14. int main()
  15. {
  16. std::unique_ptr<A> a_obj;
  17. try {
  18. a_obj.reset(new A);
  19. } catch(std::runtime_error&) {
  20.  
  21. }
  22.  
  23. if(a_obj)
  24. std::cout << "Created.\n";
  25. else
  26. std::cout << "Operation failed.\n";
  27.  
  28. std::unique_ptr<B> b_obj;
  29. try {
  30. b_obj.reset(new B);
  31. } catch(std::runtime_error&) {
  32.  
  33. }
  34.  
  35. if(b_obj)
  36. std::cout << "Created.\n";
  37. else
  38. std::cout << "Operation failed.\n";
  39.  
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
Created.
Operation failed.