1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // The LLVM Compiler Infrastructure 5 // 6 // This file is dual licensed under the MIT and the University of Illinois Open 7 // Source Licenses. See LICENSE.TXT for details. 8 // 9 //===----------------------------------------------------------------------===// 10 11 #ifndef HAVE_DEPENDENT_EH_ABI 12 #error this header may only be used with libc++abi or libcxxrt 13 #endif 14 15 namespace std { 16 17 exception_ptr::~exception_ptr() _NOEXCEPT { 18 __cxa_decrement_exception_refcount(__ptr_); 19 } 20 21 exception_ptr::exception_ptr(const exception_ptr& other) _NOEXCEPT 22 : __ptr_(other.__ptr_) 23 { 24 __cxa_increment_exception_refcount(__ptr_); 25 } 26 27 exception_ptr& exception_ptr::operator=(const exception_ptr& other) _NOEXCEPT 28 { 29 if (__ptr_ != other.__ptr_) 30 { 31 __cxa_increment_exception_refcount(other.__ptr_); 32 __cxa_decrement_exception_refcount(__ptr_); 33 __ptr_ = other.__ptr_; 34 } 35 return *this; 36 } 37 38 nested_exception::nested_exception() _NOEXCEPT 39 : __ptr_(current_exception()) 40 { 41 } 42 43 nested_exception::~nested_exception() _NOEXCEPT 44 { 45 } 46 47 _LIBCPP_NORETURN 48 void 49 nested_exception::rethrow_nested() const 50 { 51 if (__ptr_ == nullptr) 52 terminate(); 53 rethrow_exception(__ptr_); 54 } 55 56 exception_ptr current_exception() _NOEXCEPT 57 { 58 // be nicer if there was a constructor that took a ptr, then 59 // this whole function would be just: 60 // return exception_ptr(__cxa_current_primary_exception()); 61 exception_ptr ptr; 62 ptr.__ptr_ = __cxa_current_primary_exception(); 63 return ptr; 64 } 65 66 _LIBCPP_NORETURN 67 void rethrow_exception(exception_ptr p) 68 { 69 __cxa_rethrow_primary_exception(p.__ptr_); 70 // if p.__ptr_ is NULL, above returns so we terminate 71 terminate(); 72 } 73 74 } // namespace std 75