1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // The LLVM Compiler Infrastructure 5 // 6 // This file is dual licensed under the MIT and the University of Illinois Open 7 // Source Licenses. See LICENSE.TXT for details. 8 // 9 //===----------------------------------------------------------------------===// 10 11 #ifndef _LIBCPP_ABI_MICROSOFT 12 #error this header can only be used when targeting the MSVC ABI 13 #endif 14 15 #include <stdio.h> 16 #include <stdlib.h> 17 18 extern "C" { 19 typedef void (__cdecl* terminate_handler)(); 20 _LIBCPP_CRT_FUNC terminate_handler __cdecl set_terminate( 21 terminate_handler _NewTerminateHandler) throw(); 22 _LIBCPP_CRT_FUNC terminate_handler __cdecl _get_terminate(); 23 24 typedef void (__cdecl* unexpected_handler)(); 25 unexpected_handler __cdecl set_unexpected( 26 unexpected_handler _NewUnexpectedHandler) throw(); 27 unexpected_handler __cdecl _get_unexpected(); 28 29 int __cdecl __uncaught_exceptions(); 30 } 31 32 namespace std { 33 34 unexpected_handler 35 set_unexpected(unexpected_handler func) _NOEXCEPT { 36 return ::set_unexpected(func); 37 } 38 39 unexpected_handler get_unexpected() _NOEXCEPT { 40 return ::_get_unexpected(); 41 } 42 43 _LIBCPP_NORETURN 44 void unexpected() { 45 (*get_unexpected())(); 46 // unexpected handler should not return 47 terminate(); 48 } 49 50 terminate_handler set_terminate(terminate_handler func) _NOEXCEPT { 51 return ::set_terminate(func); 52 } 53 54 terminate_handler get_terminate() _NOEXCEPT { 55 return ::_get_terminate(); 56 } 57 58 _LIBCPP_NORETURN 59 void terminate() _NOEXCEPT 60 { 61 #ifndef _LIBCPP_NO_EXCEPTIONS 62 try 63 { 64 #endif // _LIBCPP_NO_EXCEPTIONS 65 (*get_terminate())(); 66 // handler should not return 67 fprintf(stderr, "terminate_handler unexpectedly returned\n"); 68 ::abort(); 69 #ifndef _LIBCPP_NO_EXCEPTIONS 70 } 71 catch (...) 72 { 73 // handler should not throw exception 74 fprintf(stderr, "terminate_handler unexpectedly threw an exception\n"); 75 ::abort(); 76 } 77 #endif // _LIBCPP_NO_EXCEPTIONS 78 } 79 80 bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; } 81 82 int uncaught_exceptions() _NOEXCEPT { 83 return __uncaught_exceptions(); 84 } 85 86 bad_array_length::bad_array_length() _NOEXCEPT 87 { 88 } 89 90 bad_array_length::~bad_array_length() _NOEXCEPT 91 { 92 } 93 94 const char* 95 bad_array_length::what() const _NOEXCEPT 96 { 97 return "bad_array_length"; 98 } 99 100 #if defined(_LIBCPP_NO_VCRUNTIME) 101 bad_cast::bad_cast() _NOEXCEPT 102 { 103 } 104 105 bad_cast::~bad_cast() _NOEXCEPT 106 { 107 } 108 109 const char * 110 bad_cast::what() const _NOEXCEPT 111 { 112 return "std::bad_cast"; 113 } 114 115 bad_typeid::bad_typeid() _NOEXCEPT 116 { 117 } 118 119 bad_typeid::~bad_typeid() _NOEXCEPT 120 { 121 } 122 123 const char * 124 bad_typeid::what() const _NOEXCEPT 125 { 126 return "std::bad_typeid"; 127 } 128 129 exception::~exception() _NOEXCEPT 130 { 131 } 132 133 const char* exception::what() const _NOEXCEPT 134 { 135 return "std::exception"; 136 } 137 138 139 bad_exception::~bad_exception() _NOEXCEPT 140 { 141 } 142 143 const char* bad_exception::what() const _NOEXCEPT 144 { 145 return "std::bad_exception"; 146 } 147 148 149 bad_alloc::bad_alloc() _NOEXCEPT 150 { 151 } 152 153 bad_alloc::~bad_alloc() _NOEXCEPT 154 { 155 } 156 157 const char* 158 bad_alloc::what() const _NOEXCEPT 159 { 160 return "std::bad_alloc"; 161 } 162 163 bad_array_new_length::bad_array_new_length() _NOEXCEPT 164 { 165 } 166 167 bad_array_new_length::~bad_array_new_length() _NOEXCEPT 168 { 169 } 170 171 const char* 172 bad_array_new_length::what() const _NOEXCEPT 173 { 174 return "bad_array_new_length"; 175 } 176 #endif // _LIBCPP_NO_VCRUNTIME 177 178 } // namespace std 179