2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef HAVE_DEPENDENT_EH_ABI
11 #error this header may only be used with libc++abi or libcxxrt
16 exception_ptr::~exception_ptr() noexcept {
17 __cxa_decrement_exception_refcount(__ptr_);
20 exception_ptr::exception_ptr(const exception_ptr& other) noexcept
21 : __ptr_(other.__ptr_)
23 __cxa_increment_exception_refcount(__ptr_);
26 exception_ptr& exception_ptr::operator=(const exception_ptr& other) noexcept
28 if (__ptr_ != other.__ptr_)
30 __cxa_increment_exception_refcount(other.__ptr_);
31 __cxa_decrement_exception_refcount(__ptr_);
32 __ptr_ = other.__ptr_;
37 nested_exception::nested_exception() noexcept
38 : __ptr_(current_exception())
42 nested_exception::~nested_exception() noexcept
48 nested_exception::rethrow_nested() const
50 if (__ptr_ == nullptr)
52 rethrow_exception(__ptr_);
55 exception_ptr current_exception() noexcept
57 // be nicer if there was a constructor that took a ptr, then
58 // this whole function would be just:
59 // return exception_ptr(__cxa_current_primary_exception());
61 ptr.__ptr_ = __cxa_current_primary_exception();
66 void rethrow_exception(exception_ptr p)
68 __cxa_rethrow_primary_exception(p.__ptr_);
69 // if p.__ptr_ is NULL, above returns so we terminate