Advertisement
TwITe

Untitled

Dec 30th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <memory>
  3. using namespace std;
  4.  
  5. class A {
  6. public:
  7.     unique_ptr<int[]> data;
  8.  
  9.     A(int* d) : data(d) {
  10.         throw runtime_error("err");
  11.     }
  12.  
  13.     ~A() {
  14.         cout << "A's destructor was called" << endl;
  15.     }
  16. };
  17.  
  18. class B {
  19. public:
  20.     unique_ptr<int[]> data2;
  21.     unique_ptr<A> a;
  22.  
  23.     B() try : data2(new int[10]), a(new A(new int[3])) {}
  24.     catch (exception e) {}
  25.  
  26.     ~B() {
  27.         cout << "B's destructor was called" << endl;
  28.     }
  29. };
  30.  
  31. int main() {
  32.     try {
  33. //        int arr[] = {1,2,3};
  34. //        B c(arr);
  35.         B c;
  36.     }
  37.     catch (exception e) {
  38.         cout << "EXCEPTION SUCK";
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement