1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <exception> 11 12 // class nested_exception; 13 14 // nested_exception() throw(); 15 16 #include <exception> 17 #include <cassert> 18 19 class A 20 { 21 int data_; 22 public: A(int data)23 explicit A(int data) : data_(data) {} 24 operator ==(const A & x,const A & y)25 friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;} 26 }; 27 main()28int main() 29 { 30 { 31 std::nested_exception e; 32 assert(e.nested_ptr() == nullptr); 33 } 34 { 35 try 36 { 37 throw A(2); 38 assert(false); 39 } 40 catch (const A&) 41 { 42 std::nested_exception e; 43 assert(e.nested_ptr() != nullptr); 44 try 45 { 46 rethrow_exception(e.nested_ptr()); 47 assert(false); 48 } 49 catch (const A& a) 50 { 51 assert(a == A(2)); 52 } 53 } 54 } 55 } 56