ed2c2916b2
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@104850 91177308-0d34-0410-b5e6-96231b3b80d8
74 lines
1.4 KiB
C++
74 lines
1.4 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// 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) {}
|
|
|
|
friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;}
|
|
};
|
|
|
|
class B
|
|
: public std::nested_exception
|
|
{
|
|
int data_;
|
|
public:
|
|
explicit B(int data) : data_(data) {}
|
|
B(const B& b) : data_(b.data_) {}
|
|
|
|
friend bool operator==(const B& x, const B& y) {return x.data_ == y.data_;}
|
|
};
|
|
|
|
int main()
|
|
{
|
|
{
|
|
try
|
|
{
|
|
A a(3);
|
|
std::rethrow_if_nested(a);
|
|
assert(true);
|
|
}
|
|
catch (...)
|
|
{
|
|
assert(false);
|
|
}
|
|
}
|
|
{
|
|
try
|
|
{
|
|
throw B(5);
|
|
}
|
|
catch (const B& b0)
|
|
{
|
|
try
|
|
{
|
|
B b = b0;
|
|
std::rethrow_if_nested(b);
|
|
assert(false);
|
|
}
|
|
catch (const B& b)
|
|
{
|
|
assert(b == B(5));
|
|
}
|
|
}
|
|
}
|
|
}
|