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 { __cxa_decrement_exception_refcount(__ptr_); }
18 exception_ptr::exception_ptr(const exception_ptr& other) noexcept : __ptr_(other.__ptr_) {
19 __cxa_increment_exception_refcount(__ptr_);
22 exception_ptr& exception_ptr::operator=(const exception_ptr& other) noexcept {
23 if (__ptr_ != other.__ptr_) {
24 __cxa_increment_exception_refcount(other.__ptr_);
25 __cxa_decrement_exception_refcount(__ptr_);
26 __ptr_ = other.__ptr_;
31 exception_ptr exception_ptr::__from_native_exception_pointer(void* __e) noexcept {
34 __cxa_increment_exception_refcount(ptr.__ptr_);
39 nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {}
41 nested_exception::~nested_exception() noexcept {}
43 void nested_exception::rethrow_nested() const {
44 if (__ptr_ == nullptr)
46 rethrow_exception(__ptr_);
49 exception_ptr current_exception() noexcept {
50 // be nicer if there was a constructor that took a ptr, then
51 // this whole function would be just:
52 // return exception_ptr(__cxa_current_primary_exception());
54 ptr.__ptr_ = __cxa_current_primary_exception();
58 void rethrow_exception(exception_ptr p) {
59 __cxa_rethrow_primary_exception(p.__ptr_);
60 // if p.__ptr_ is NULL, above returns so we terminate