Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 1 | //===------------------------ exception.cpp -------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | #include <stdlib.h> |
Howard Hinnant | ed14a76 | 2013-07-23 16:05:56 +0000 | [diff] [blame] | 10 | #include <stdio.h> |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 11 | |
| 12 | #include "exception" |
Peter Collingbourne | ece9591 | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 13 | #include "new" |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 14 | |
Richard Smith | 591e32d | 2012-07-11 09:35:47 +0000 | [diff] [blame] | 15 | #ifndef __has_include |
| 16 | #define __has_include(inc) 0 |
| 17 | #endif |
| 18 | |
Marshall Clow | dece7fe | 2013-03-18 17:45:34 +0000 | [diff] [blame] | 19 | #ifdef __APPLE__ |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 20 | #include <cxxabi.h> |
Howard Hinnant | dea7f39 | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 21 | |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 22 | using namespace __cxxabiv1; |
David Chisnall | c512df1 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 23 | #define HAVE_DEPENDENT_EH_ABI 1 |
Howard Hinnant | dea7f39 | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 24 | #ifndef _LIBCPPABI_VERSION |
| 25 | using namespace __cxxabiapple; |
| 26 | // On Darwin, there are two STL shared libraries and a lower level ABI |
Marshall Clow | a46a0ad | 2013-11-11 23:27:19 +0000 | [diff] [blame] | 27 | // shared library. The globals holding the current terminate handler and |
Howard Hinnant | dea7f39 | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 28 | // current unexpected handler are in the ABI library. |
| 29 | #define __terminate_handler __cxxabiapple::__cxa_terminate_handler |
| 30 | #define __unexpected_handler __cxxabiapple::__cxa_unexpected_handler |
| 31 | #endif // _LIBCPPABI_VERSION |
Richard Smith | 591e32d | 2012-07-11 09:35:47 +0000 | [diff] [blame] | 32 | #elif defined(LIBCXXRT) || __has_include(<cxxabi.h>) |
David Chisnall | c512df1 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 33 | #include <cxxabi.h> |
| 34 | using namespace __cxxabiv1; |
Richard Smith | 591e32d | 2012-07-11 09:35:47 +0000 | [diff] [blame] | 35 | #if defined(LIBCXXRT) || defined(_LIBCPPABI_VERSION) |
| 36 | #define HAVE_DEPENDENT_EH_ABI 1 |
| 37 | #endif |
Howard Hinnant | e0f0bfb | 2013-01-22 14:48:10 +0000 | [diff] [blame] | 38 | #elif !defined(__GLIBCXX__) // __has_include(<cxxabi.h>) |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 39 | static std::terminate_handler __terminate_handler; |
| 40 | static std::unexpected_handler __unexpected_handler; |
Richard Smith | 591e32d | 2012-07-11 09:35:47 +0000 | [diff] [blame] | 41 | #endif // __has_include(<cxxabi.h>) |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 42 | |
David Chisnall | 1e8b3f9 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 43 | namespace std |
| 44 | { |
| 45 | |
Michael J. Spencer | a358fbe | 2012-11-30 21:02:29 +0000 | [diff] [blame] | 46 | #if !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION) && !defined(__GLIBCXX__) |
Howard Hinnant | dea7f39 | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 47 | |
David Chisnall | c512df1 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 48 | // libcxxrt provides implementations of these functions itself. |
David Chisnall | 1e8b3f9 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 49 | unexpected_handler |
| 50 | set_unexpected(unexpected_handler func) _NOEXCEPT |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 51 | { |
Howard Hinnant | a445151 | 2010-12-02 16:45:21 +0000 | [diff] [blame] | 52 | return __sync_lock_test_and_set(&__unexpected_handler, func); |
| 53 | } |
| 54 | |
David Chisnall | 1e8b3f9 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 55 | unexpected_handler |
| 56 | get_unexpected() _NOEXCEPT |
Howard Hinnant | a445151 | 2010-12-02 16:45:21 +0000 | [diff] [blame] | 57 | { |
David Chisnall | 1e8b3f9 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 58 | return __sync_fetch_and_add(&__unexpected_handler, (unexpected_handler)0); |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Richard Smith | 0405cc4 | 2012-07-26 02:04:22 +0000 | [diff] [blame] | 61 | _LIBCPP_NORETURN |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 62 | void |
David Chisnall | 1e8b3f9 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 63 | unexpected() |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 64 | { |
David Chisnall | 1e8b3f9 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 65 | (*get_unexpected())(); |
Howard Hinnant | d510977 | 2010-08-22 13:53:14 +0000 | [diff] [blame] | 66 | // unexpected handler should not return |
David Chisnall | 1e8b3f9 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 67 | terminate(); |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 68 | } |
| 69 | |
David Chisnall | 1e8b3f9 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 70 | terminate_handler |
| 71 | set_terminate(terminate_handler func) _NOEXCEPT |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 72 | { |
Howard Hinnant | a445151 | 2010-12-02 16:45:21 +0000 | [diff] [blame] | 73 | return __sync_lock_test_and_set(&__terminate_handler, func); |
| 74 | } |
| 75 | |
David Chisnall | 1e8b3f9 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 76 | terminate_handler |
| 77 | get_terminate() _NOEXCEPT |
Howard Hinnant | a445151 | 2010-12-02 16:45:21 +0000 | [diff] [blame] | 78 | { |
David Chisnall | 1e8b3f9 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 79 | return __sync_fetch_and_add(&__terminate_handler, (terminate_handler)0); |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Marshall Clow | 2ccffef | 2013-11-19 18:05:03 +0000 | [diff] [blame] | 82 | #ifndef __EMSCRIPTEN__ // We provide this in JS |
Richard Smith | 0405cc4 | 2012-07-26 02:04:22 +0000 | [diff] [blame] | 83 | _LIBCPP_NORETURN |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 84 | void |
David Chisnall | 1e8b3f9 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 85 | terminate() _NOEXCEPT |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 86 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 87 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 88 | try |
| 89 | { |
Howard Hinnant | 16e6e1d | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 90 | #endif // _LIBCPP_NO_EXCEPTIONS |
David Chisnall | 1e8b3f9 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 91 | (*get_terminate())(); |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 92 | // handler should not return |
Peter Collingbourne | 4a0555a | 2013-10-06 22:13:24 +0000 | [diff] [blame] | 93 | printf("terminate_handler unexpectedly returned\n"); |
| 94 | ::abort(); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 95 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 16e6e1d | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 96 | } |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 97 | catch (...) |
| 98 | { |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 99 | // handler should not throw exception |
Peter Collingbourne | 4a0555a | 2013-10-06 22:13:24 +0000 | [diff] [blame] | 100 | printf("terminate_handler unexpectedly threw an exception\n"); |
| 101 | ::abort(); |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 102 | } |
Howard Hinnant | 16e6e1d | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 103 | #endif // _LIBCPP_NO_EXCEPTIONS |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 104 | } |
Marshall Clow | 2ccffef | 2013-11-19 18:05:03 +0000 | [diff] [blame] | 105 | #endif // !__EMSCRIPTEN__ |
Howard Hinnant | dea7f39 | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 106 | #endif // !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION) |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 107 | |
Marshall Clow | 2ccffef | 2013-11-19 18:05:03 +0000 | [diff] [blame] | 108 | #if !defined(LIBCXXRT) && !defined(__GLIBCXX__) && !defined(__EMSCRIPTEN__) |
David Chisnall | 1e8b3f9 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 109 | bool uncaught_exception() _NOEXCEPT |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 110 | { |
Marshall Clow | dece7fe | 2013-03-18 17:45:34 +0000 | [diff] [blame] | 111 | #if defined(__APPLE__) || defined(_LIBCPPABI_VERSION) |
Howard Hinnant | d510977 | 2010-08-22 13:53:14 +0000 | [diff] [blame] | 112 | // on Darwin, there is a helper function so __cxa_get_globals is private |
Howard Hinnant | dea7f39 | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 113 | return __cxa_uncaught_exception(); |
Howard Hinnant | d0ed21e | 2012-02-29 15:37:30 +0000 | [diff] [blame] | 114 | #else // __APPLE__ |
Howard Hinnant | f755506 | 2013-10-04 21:14:44 +0000 | [diff] [blame] | 115 | # if defined(_MSC_VER) && ! defined(__clang__) |
| 116 | _LIBCPP_WARNING("uncaught_exception not yet implemented") |
| 117 | # else |
| 118 | # warning uncaught_exception not yet implemented |
| 119 | # endif |
Peter Collingbourne | 4a0555a | 2013-10-06 22:13:24 +0000 | [diff] [blame] | 120 | printf("uncaught_exception not yet implemented\n"); |
| 121 | ::abort(); |
Howard Hinnant | 16e6e1d | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 122 | #endif // __APPLE__ |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Howard Hinnant | f755506 | 2013-10-04 21:14:44 +0000 | [diff] [blame] | 125 | |
Howard Hinnant | dea7f39 | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 126 | #ifndef _LIBCPPABI_VERSION |
| 127 | |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 128 | exception::~exception() _NOEXCEPT |
Howard Hinnant | 16e6e1d | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 129 | { |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 132 | const char* exception::what() const _NOEXCEPT |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 133 | { |
| 134 | return "std::exception"; |
| 135 | } |
| 136 | |
David Chisnall | 21a84cf | 2012-03-14 14:11:13 +0000 | [diff] [blame] | 137 | #endif // _LIBCPPABI_VERSION |
| 138 | #endif //LIBCXXRT |
Michael J. Spencer | a358fbe | 2012-11-30 21:02:29 +0000 | [diff] [blame] | 139 | #if !defined(_LIBCPPABI_VERSION) && !defined(__GLIBCXX__) |
David Chisnall | 21a84cf | 2012-03-14 14:11:13 +0000 | [diff] [blame] | 140 | |
| 141 | bad_exception::~bad_exception() _NOEXCEPT |
| 142 | { |
| 143 | } |
| 144 | |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 145 | const char* bad_exception::what() const _NOEXCEPT |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 146 | { |
| 147 | return "std::bad_exception"; |
| 148 | } |
| 149 | |
David Chisnall | 21a84cf | 2012-03-14 14:11:13 +0000 | [diff] [blame] | 150 | #endif |
| 151 | |
Peter Collingbourne | ece9591 | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 152 | #if defined(__GLIBCXX__) |
| 153 | |
| 154 | // libsupc++ does not implement the dependent EH ABI and the functionality |
| 155 | // it uses to implement std::exception_ptr (which it declares as an alias of |
| 156 | // std::__exception_ptr::exception_ptr) is not directly exported to clients. So |
| 157 | // we have little choice but to hijack std::__exception_ptr::exception_ptr's |
| 158 | // (which fortunately has the same layout as our std::exception_ptr) copy |
| 159 | // constructor, assignment operator and destructor (which are part of its |
| 160 | // stable ABI), and its rethrow_exception(std::__exception_ptr::exception_ptr) |
| 161 | // function. |
| 162 | |
| 163 | namespace __exception_ptr |
| 164 | { |
| 165 | |
| 166 | struct exception_ptr |
| 167 | { |
| 168 | void* __ptr_; |
| 169 | |
| 170 | exception_ptr(const exception_ptr&) _NOEXCEPT; |
| 171 | exception_ptr& operator=(const exception_ptr&) _NOEXCEPT; |
| 172 | ~exception_ptr() _NOEXCEPT; |
| 173 | }; |
| 174 | |
| 175 | } |
| 176 | |
| 177 | _LIBCPP_NORETURN void rethrow_exception(__exception_ptr::exception_ptr); |
| 178 | |
| 179 | #endif |
Howard Hinnant | dea7f39 | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 180 | |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 181 | exception_ptr::~exception_ptr() _NOEXCEPT |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 182 | { |
David Chisnall | c512df1 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 183 | #if HAVE_DEPENDENT_EH_ABI |
| 184 | __cxa_decrement_exception_refcount(__ptr_); |
Peter Collingbourne | ece9591 | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 185 | #elif defined(__GLIBCXX__) |
| 186 | reinterpret_cast<__exception_ptr::exception_ptr*>(this)->~exception_ptr(); |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 187 | #else |
Howard Hinnant | f755506 | 2013-10-04 21:14:44 +0000 | [diff] [blame] | 188 | # if defined(_MSC_VER) && ! defined(__clang__) |
| 189 | _LIBCPP_WARNING("exception_ptr not yet implemented") |
| 190 | # else |
| 191 | # warning exception_ptr not yet implemented |
| 192 | # endif |
Peter Collingbourne | 4a0555a | 2013-10-06 22:13:24 +0000 | [diff] [blame] | 193 | printf("exception_ptr not yet implemented\n"); |
| 194 | ::abort(); |
Peter Collingbourne | ece9591 | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 195 | #endif |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 198 | exception_ptr::exception_ptr(const exception_ptr& other) _NOEXCEPT |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 199 | : __ptr_(other.__ptr_) |
| 200 | { |
David Chisnall | c512df1 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 201 | #if HAVE_DEPENDENT_EH_ABI |
| 202 | __cxa_increment_exception_refcount(__ptr_); |
Peter Collingbourne | ece9591 | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 203 | #elif defined(__GLIBCXX__) |
| 204 | new (reinterpret_cast<void*>(this)) __exception_ptr::exception_ptr( |
| 205 | reinterpret_cast<const __exception_ptr::exception_ptr&>(other)); |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 206 | #else |
Howard Hinnant | f755506 | 2013-10-04 21:14:44 +0000 | [diff] [blame] | 207 | # if defined(_MSC_VER) && ! defined(__clang__) |
| 208 | _LIBCPP_WARNING("exception_ptr not yet implemented") |
| 209 | # else |
| 210 | # warning exception_ptr not yet implemented |
| 211 | # endif |
Peter Collingbourne | 4a0555a | 2013-10-06 22:13:24 +0000 | [diff] [blame] | 212 | printf("exception_ptr not yet implemented\n"); |
| 213 | ::abort(); |
Peter Collingbourne | ece9591 | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 214 | #endif |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 217 | exception_ptr& exception_ptr::operator=(const exception_ptr& other) _NOEXCEPT |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 218 | { |
David Chisnall | c512df1 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 219 | #if HAVE_DEPENDENT_EH_ABI |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 220 | if (__ptr_ != other.__ptr_) |
| 221 | { |
David Chisnall | c512df1 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 222 | __cxa_increment_exception_refcount(other.__ptr_); |
| 223 | __cxa_decrement_exception_refcount(__ptr_); |
Howard Hinnant | d510977 | 2010-08-22 13:53:14 +0000 | [diff] [blame] | 224 | __ptr_ = other.__ptr_; |
| 225 | } |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 226 | return *this; |
Peter Collingbourne | ece9591 | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 227 | #elif defined(__GLIBCXX__) |
| 228 | *reinterpret_cast<__exception_ptr::exception_ptr*>(this) = |
| 229 | reinterpret_cast<const __exception_ptr::exception_ptr&>(other); |
| 230 | return *this; |
| 231 | #else |
Howard Hinnant | f755506 | 2013-10-04 21:14:44 +0000 | [diff] [blame] | 232 | # if defined(_MSC_VER) && ! defined(__clang__) |
| 233 | _LIBCPP_WARNING("exception_ptr not yet implemented") |
| 234 | # else |
| 235 | # warning exception_ptr not yet implemented |
| 236 | # endif |
Peter Collingbourne | 4a0555a | 2013-10-06 22:13:24 +0000 | [diff] [blame] | 237 | printf("exception_ptr not yet implemented\n"); |
| 238 | ::abort(); |
Peter Collingbourne | ece9591 | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 239 | #endif |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 240 | } |
| 241 | |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 242 | nested_exception::nested_exception() _NOEXCEPT |
Howard Hinnant | ed2c291 | 2010-05-27 17:06:52 +0000 | [diff] [blame] | 243 | : __ptr_(current_exception()) |
| 244 | { |
| 245 | } |
| 246 | |
Peter Collingbourne | 40455c6 | 2013-10-06 22:13:16 +0000 | [diff] [blame] | 247 | #if !defined(__GLIBCXX__) |
| 248 | |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 249 | nested_exception::~nested_exception() _NOEXCEPT |
Howard Hinnant | ed2c291 | 2010-05-27 17:06:52 +0000 | [diff] [blame] | 250 | { |
| 251 | } |
| 252 | |
Peter Collingbourne | 40455c6 | 2013-10-06 22:13:16 +0000 | [diff] [blame] | 253 | #endif |
| 254 | |
Richard Smith | 0405cc4 | 2012-07-26 02:04:22 +0000 | [diff] [blame] | 255 | _LIBCPP_NORETURN |
Howard Hinnant | ed2c291 | 2010-05-27 17:06:52 +0000 | [diff] [blame] | 256 | void |
Howard Hinnant | 4b7a43d | 2011-05-26 17:07:32 +0000 | [diff] [blame] | 257 | nested_exception::rethrow_nested() const |
Howard Hinnant | ed2c291 | 2010-05-27 17:06:52 +0000 | [diff] [blame] | 258 | { |
| 259 | if (__ptr_ == nullptr) |
| 260 | terminate(); |
| 261 | rethrow_exception(__ptr_); |
| 262 | } |
| 263 | |
Peter Collingbourne | ece9591 | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 264 | #if !defined(__GLIBCXX__) |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 265 | |
David Chisnall | 1e8b3f9 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 266 | exception_ptr current_exception() _NOEXCEPT |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 267 | { |
David Chisnall | c512df1 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 268 | #if HAVE_DEPENDENT_EH_ABI |
Howard Hinnant | d510977 | 2010-08-22 13:53:14 +0000 | [diff] [blame] | 269 | // be nicer if there was a constructor that took a ptr, then |
| 270 | // this whole function would be just: |
| 271 | // return exception_ptr(__cxa_current_primary_exception()); |
David Chisnall | 1e8b3f9 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 272 | exception_ptr ptr; |
David Chisnall | c512df1 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 273 | ptr.__ptr_ = __cxa_current_primary_exception(); |
Howard Hinnant | d510977 | 2010-08-22 13:53:14 +0000 | [diff] [blame] | 274 | return ptr; |
Peter Collingbourne | ece9591 | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 275 | #else |
Howard Hinnant | f755506 | 2013-10-04 21:14:44 +0000 | [diff] [blame] | 276 | # if defined(_MSC_VER) && ! defined(__clang__) |
| 277 | _LIBCPP_WARNING( "exception_ptr not yet implemented" ) |
| 278 | # else |
| 279 | # warning exception_ptr not yet implemented |
| 280 | # endif |
Peter Collingbourne | 4a0555a | 2013-10-06 22:13:24 +0000 | [diff] [blame] | 281 | printf("exception_ptr not yet implemented\n"); |
| 282 | ::abort(); |
Peter Collingbourne | ece9591 | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 283 | #endif |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Peter Collingbourne | ece9591 | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 286 | #endif // !__GLIBCXX__ |
| 287 | |
Richard Smith | 0405cc4 | 2012-07-26 02:04:22 +0000 | [diff] [blame] | 288 | _LIBCPP_NORETURN |
David Chisnall | 1e8b3f9 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 289 | void rethrow_exception(exception_ptr p) |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 290 | { |
David Chisnall | c512df1 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 291 | #if HAVE_DEPENDENT_EH_ABI |
| 292 | __cxa_rethrow_primary_exception(p.__ptr_); |
Howard Hinnant | d510977 | 2010-08-22 13:53:14 +0000 | [diff] [blame] | 293 | // if p.__ptr_ is NULL, above returns so we terminate |
Howard Hinnant | 16e6e1d | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 294 | terminate(); |
Peter Collingbourne | ece9591 | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 295 | #elif defined(__GLIBCXX__) |
| 296 | rethrow_exception(reinterpret_cast<__exception_ptr::exception_ptr&>(p)); |
| 297 | #else |
Howard Hinnant | f755506 | 2013-10-04 21:14:44 +0000 | [diff] [blame] | 298 | # if defined(_MSC_VER) && ! defined(__clang__) |
| 299 | _LIBCPP_WARNING("exception_ptr not yet implemented") |
| 300 | # else |
| 301 | # warning exception_ptr not yet implemented |
| 302 | # endif |
Peter Collingbourne | 4a0555a | 2013-10-06 22:13:24 +0000 | [diff] [blame] | 303 | printf("exception_ptr not yet implemented\n"); |
| 304 | ::abort(); |
Peter Collingbourne | ece9591 | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 305 | #endif |
Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 306 | } |
David Chisnall | 1e8b3f9 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 307 | } // std |