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> |
| 17 | #include <eh.h> |
| 18 | #include <corecrt_terminate.h> |
| 19 | |
| 20 | namespace std { |
| 21 | |
| 22 | // libcxxrt provides implementations of these functions itself. |
| 23 | unexpected_handler |
| 24 | set_unexpected(unexpected_handler func) _NOEXCEPT { |
| 25 | return ::set_unexpected(func); |
| 26 | } |
| 27 | |
| 28 | unexpected_handler get_unexpected() _NOEXCEPT { |
| 29 | return ::_get_unexpected(); |
| 30 | } |
| 31 | |
| 32 | _LIBCPP_NORETURN |
| 33 | void unexpected() { |
| 34 | (*get_unexpected())(); |
| 35 | // unexpected handler should not return |
| 36 | terminate(); |
| 37 | } |
| 38 | |
| 39 | terminate_handler set_terminate(terminate_handler func) _NOEXCEPT { |
| 40 | return ::set_terminate(func); |
| 41 | } |
| 42 | |
| 43 | terminate_handler get_terminate() _NOEXCEPT { |
| 44 | return ::_get_terminate(); |
| 45 | } |
| 46 | |
| 47 | _LIBCPP_NORETURN |
| 48 | void terminate() _NOEXCEPT |
| 49 | { |
| 50 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 51 | try |
| 52 | { |
| 53 | #endif // _LIBCPP_NO_EXCEPTIONS |
| 54 | (*get_terminate())(); |
| 55 | // handler should not return |
| 56 | fprintf(stderr, "terminate_handler unexpectedly returned\n"); |
| 57 | ::abort(); |
| 58 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 59 | } |
| 60 | catch (...) |
| 61 | { |
| 62 | // handler should not throw exception |
| 63 | fprintf(stderr, "terminate_handler unexpectedly threw an exception\n"); |
| 64 | ::abort(); |
| 65 | } |
| 66 | #endif // _LIBCPP_NO_EXCEPTIONS |
| 67 | } |
| 68 | |
| 69 | bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; } |
| 70 | |
| 71 | int uncaught_exceptions() _NOEXCEPT { |
| 72 | return __uncaught_exceptions(); |
| 73 | } |
| 74 | |
| 75 | bad_array_length::bad_array_length() _NOEXCEPT |
| 76 | { |
| 77 | } |
| 78 | |
| 79 | bad_array_length::~bad_array_length() _NOEXCEPT |
| 80 | { |
| 81 | } |
| 82 | |
| 83 | const char* |
| 84 | bad_array_length::what() const _NOEXCEPT |
| 85 | { |
| 86 | return "bad_array_length"; |
| 87 | } |
| 88 | |
Saleem Abdulrasool | e7b38cd | 2017-09-15 05:42:39 +0000 | [diff] [blame^] | 89 | bad_cast::bad_cast() _NOEXCEPT |
| 90 | { |
| 91 | } |
| 92 | |
| 93 | bad_cast::~bad_cast() _NOEXCEPT |
| 94 | { |
| 95 | } |
| 96 | |
| 97 | const char * |
| 98 | bad_cast::what() const _NOEXCEPT |
| 99 | { |
| 100 | return "std::bad_cast"; |
| 101 | } |
| 102 | |
| 103 | bad_typeid::bad_typeid() _NOEXCEPT |
| 104 | { |
| 105 | } |
| 106 | |
| 107 | bad_typeid::~bad_typeid() _NOEXCEPT |
| 108 | { |
| 109 | } |
| 110 | |
| 111 | const char * |
| 112 | bad_typeid::what() const _NOEXCEPT |
| 113 | { |
| 114 | return "std::bad_typeid"; |
| 115 | } |
| 116 | |
Eric Fiselier | d22c9dc | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 117 | } // namespace std |