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 //===----------------------------------------------------------------------===//
14 static constinit std::terminate_handler __terminate_handler = nullptr;
15 static constinit std::unexpected_handler __unexpected_handler = nullptr;
17 // libcxxrt provides implementations of these functions itself.
19 set_unexpected(unexpected_handler func) noexcept
21 return __libcpp_atomic_exchange(&__unexpected_handler, func);
25 get_unexpected() noexcept
27 return __libcpp_atomic_load(&__unexpected_handler);
33 (*get_unexpected())();
34 // unexpected handler should not return
39 set_terminate(terminate_handler func) noexcept
41 return __libcpp_atomic_exchange(&__terminate_handler, func);
45 get_terminate() noexcept
47 return __libcpp_atomic_load(&__terminate_handler);
54 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
57 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
59 // handler should not return
60 fprintf(stderr, "terminate_handler unexpectedly returned\n");
62 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
66 // handler should not throw exception
67 fprintf(stderr, "terminate_handler unexpectedly threw an exception\n");
70 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
73 bool uncaught_exception() noexcept { return uncaught_exceptions() > 0; }
75 int uncaught_exceptions() noexcept
77 #warning uncaught_exception not yet implemented
78 fprintf(stderr, "uncaught_exceptions not yet implemented\n");
83 exception::~exception() noexcept
87 const char* exception::what() const noexcept
89 return "std::exception";
92 bad_exception::~bad_exception() noexcept
96 const char* bad_exception::what() const noexcept
98 return "std::bad_exception";
102 bad_alloc::bad_alloc() noexcept
106 bad_alloc::~bad_alloc() noexcept
111 bad_alloc::what() const noexcept
113 return "std::bad_alloc";
116 bad_array_new_length::bad_array_new_length() noexcept
120 bad_array_new_length::~bad_array_new_length() noexcept
125 bad_array_new_length::what() const noexcept
127 return "bad_array_new_length";
130 bad_cast::bad_cast() noexcept
134 bad_typeid::bad_typeid() noexcept
138 bad_cast::~bad_cast() noexcept
143 bad_cast::what() const noexcept
145 return "std::bad_cast";
148 bad_typeid::~bad_typeid() noexcept
153 bad_typeid::what() const noexcept
155 return "std::bad_typeid";