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 _LIBCPP_ABI_MICROSOFT
11 #error this header can only be used when targeting the MSVC ABI
18 typedef void (__cdecl* terminate_handler)();
19 _LIBCPP_CRT_FUNC terminate_handler __cdecl set_terminate(
20 terminate_handler _NewTerminateHandler) throw();
21 _LIBCPP_CRT_FUNC terminate_handler __cdecl _get_terminate();
23 typedef void (__cdecl* unexpected_handler)();
24 unexpected_handler __cdecl set_unexpected(
25 unexpected_handler _NewUnexpectedHandler) throw();
26 unexpected_handler __cdecl _get_unexpected();
28 int __cdecl __uncaught_exceptions();
34 set_unexpected(unexpected_handler func) noexcept {
35 return ::set_unexpected(func);
38 unexpected_handler get_unexpected() noexcept {
39 return ::_get_unexpected();
44 (*get_unexpected())();
45 // unexpected handler should not return
49 terminate_handler set_terminate(terminate_handler func) noexcept {
50 return ::set_terminate(func);
53 terminate_handler get_terminate() noexcept {
54 return ::_get_terminate();
58 void terminate() noexcept
60 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
63 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
65 // handler should not return
66 fprintf(stderr, "terminate_handler unexpectedly returned\n");
68 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
72 // handler should not throw exception
73 fprintf(stderr, "terminate_handler unexpectedly threw an exception\n");
76 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
79 bool uncaught_exception() noexcept { return uncaught_exceptions() > 0; }
81 int uncaught_exceptions() noexcept {
82 return __uncaught_exceptions();
85 #if !defined(_LIBCPP_ABI_VCRUNTIME)
86 bad_cast::bad_cast() noexcept
90 bad_cast::~bad_cast() noexcept
95 bad_cast::what() const noexcept
97 return "std::bad_cast";
100 bad_typeid::bad_typeid() noexcept
104 bad_typeid::~bad_typeid() noexcept
109 bad_typeid::what() const noexcept
111 return "std::bad_typeid";
114 exception::~exception() noexcept
118 const char* exception::what() const noexcept
120 return "std::exception";
124 bad_exception::~bad_exception() noexcept
128 const char* bad_exception::what() const noexcept
130 return "std::bad_exception";
134 bad_alloc::bad_alloc() noexcept
138 bad_alloc::~bad_alloc() noexcept
143 bad_alloc::what() const noexcept
145 return "std::bad_alloc";
148 bad_array_new_length::bad_array_new_length() noexcept
152 bad_array_new_length::~bad_array_new_length() noexcept
157 bad_array_new_length::what() const noexcept
159 return "bad_array_new_length";
161 #endif // !_LIBCPP_ABI_VCRUNTIME