2 //===----------------------------------------------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
15 _LIBCPP_SAFE_STATIC static std::terminate_handler __terminate_handler;
16 _LIBCPP_SAFE_STATIC static std::unexpected_handler __unexpected_handler;
19 // libcxxrt provides implementations of these functions itself.
21 set_unexpected(unexpected_handler func) _NOEXCEPT
23 return __libcpp_atomic_exchange(&__unexpected_handler, func);
27 get_unexpected() _NOEXCEPT
29 return __libcpp_atomic_load(&__unexpected_handler);
36 (*get_unexpected())();
37 // unexpected handler should not return
42 set_terminate(terminate_handler func) _NOEXCEPT
44 return __libcpp_atomic_exchange(&__terminate_handler, func);
48 get_terminate() _NOEXCEPT
50 return __libcpp_atomic_load(&__terminate_handler);
53 #ifndef __EMSCRIPTEN__ // We provide this in JS
58 #ifndef _LIBCPP_NO_EXCEPTIONS
61 #endif // _LIBCPP_NO_EXCEPTIONS
63 // handler should not return
64 fprintf(stderr, "terminate_handler unexpectedly returned\n");
66 #ifndef _LIBCPP_NO_EXCEPTIONS
70 // handler should not throw exception
71 fprintf(stderr, "terminate_handler unexpectedly threw an exception\n");
74 #endif // _LIBCPP_NO_EXCEPTIONS
76 #endif // !__EMSCRIPTEN__
78 #if !defined(__EMSCRIPTEN__)
79 bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; }
81 int uncaught_exceptions() _NOEXCEPT
83 #warning uncaught_exception not yet implemented
84 fprintf(stderr, "uncaught_exceptions not yet implemented\n");
87 #endif // !__EMSCRIPTEN__
90 exception::~exception() _NOEXCEPT
94 const char* exception::what() const _NOEXCEPT
96 return "std::exception";
99 bad_exception::~bad_exception() _NOEXCEPT
103 const char* bad_exception::what() const _NOEXCEPT
105 return "std::bad_exception";
109 bad_alloc::bad_alloc() _NOEXCEPT
113 bad_alloc::~bad_alloc() _NOEXCEPT
118 bad_alloc::what() const _NOEXCEPT
120 return "std::bad_alloc";
123 bad_array_new_length::bad_array_new_length() _NOEXCEPT
127 bad_array_new_length::~bad_array_new_length() _NOEXCEPT
132 bad_array_new_length::what() const _NOEXCEPT
134 return "bad_array_new_length";
137 bad_cast::bad_cast() _NOEXCEPT
141 bad_typeid::bad_typeid() _NOEXCEPT
145 bad_cast::~bad_cast() _NOEXCEPT
150 bad_cast::what() const _NOEXCEPT
152 return "std::bad_cast";
155 bad_typeid::~bad_typeid() _NOEXCEPT
160 bad_typeid::what() const _NOEXCEPT
162 return "std::bad_typeid";