Eric Fiselier | d22c9dc | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 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> |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 17 | |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 18 | extern "C" { |
Peter Collingbourne | 4bdb80f | 2018-01-17 04:37:04 +0000 | [diff] [blame^] | 19 | typedef void (__cdecl* terminate_handler)(); |
| 20 | _LIBCPP_CRT_FUNC terminate_handler __cdecl set_terminate( |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 21 | terminate_handler _NewTerminateHandler) throw(); |
Peter Collingbourne | 4bdb80f | 2018-01-17 04:37:04 +0000 | [diff] [blame^] | 22 | _LIBCPP_CRT_FUNC terminate_handler __cdecl _get_terminate(); |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 23 | |
Peter Collingbourne | 4bdb80f | 2018-01-17 04:37:04 +0000 | [diff] [blame^] | 24 | typedef void (__cdecl* unexpected_handler)(); |
| 25 | _LIBCPP_CRT_FUNC unexpected_handler __cdecl set_unexpected( |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 26 | unexpected_handler _NewUnexpectedHandler) throw(); |
Peter Collingbourne | 4bdb80f | 2018-01-17 04:37:04 +0000 | [diff] [blame^] | 27 | _LIBCPP_CRT_FUNC unexpected_handler __cdecl _get_unexpected(); |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 28 | |
Peter Collingbourne | 4bdb80f | 2018-01-17 04:37:04 +0000 | [diff] [blame^] | 29 | _LIBCPP_CRT_FUNC int __cdecl __uncaught_exceptions(); |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 30 | } |
Eric Fiselier | d22c9dc | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 31 | |
| 32 | namespace std { |
| 33 | |
Eric Fiselier | d22c9dc | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 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 | |
Saleem Abdulrasool | e7b38cd | 2017-09-15 05:42:39 +0000 | [diff] [blame] | 100 | bad_cast::bad_cast() _NOEXCEPT |
| 101 | { |
| 102 | } |
| 103 | |
| 104 | bad_cast::~bad_cast() _NOEXCEPT |
| 105 | { |
| 106 | } |
| 107 | |
| 108 | const char * |
| 109 | bad_cast::what() const _NOEXCEPT |
| 110 | { |
| 111 | return "std::bad_cast"; |
| 112 | } |
| 113 | |
| 114 | bad_typeid::bad_typeid() _NOEXCEPT |
| 115 | { |
| 116 | } |
| 117 | |
| 118 | bad_typeid::~bad_typeid() _NOEXCEPT |
| 119 | { |
| 120 | } |
| 121 | |
| 122 | const char * |
| 123 | bad_typeid::what() const _NOEXCEPT |
| 124 | { |
| 125 | return "std::bad_typeid"; |
| 126 | } |
| 127 | |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 128 | #if defined(_LIBCPP_NO_VCRUNTIME) |
| 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 | |
Eric Fiselier | d22c9dc | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 178 | } // namespace std |