1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- //===----------------------------------------------------------------------===//
- //
- // The LLVM Compiler Infrastructure
- //
- // This file is distributed under the University of Illinois Open Source
- // License. See LICENSE.TXT for details.
- //
- //===----------------------------------------------------------------------===//
- // <exception>
- // class nested_exception;
- // template <class E> void rethrow_if_nested(const E& e);
- #include <exception>
- #include <cstdlib>
- #include <cassert>
- class A
- {
- int data_;
- public:
- explicit A(int data) : data_(data) {}
- virtual ~A() {}
- friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;}
- };
- class B
- : public std::nested_exception,
- public A
- {
- public:
- explicit B(int data) : A(data) {}
- B(const B& b) : A(b) {}
- };
- int main()
- {
- {
- try
- {
- A a(3);
- std::rethrow_if_nested(a);
- assert(true);
- }
- catch (...)
- {
- assert(false);
- }
- }
- {
- try
- {
- throw B(5);
- }
- catch (const B& b)
- {
- try
- {
- throw b;
- }
- catch (const A& a)
- {
- try
- {
- std::rethrow_if_nested(a);
- assert(false);
- }
- catch (const B& b)
- {
- assert(b == B(5));
- }
- }
- }
- }
- {
- try
- {
- std::rethrow_if_nested(1);
- assert(true);
- }
- catch (...)
- {
- assert(false);
- }
- }
- }
|