blob: 7dc1b57d48e1728946295c2f3915096accc71e3a [file] [log] [blame]
Eric Fiselierd22c9dc2017-02-10 08:57:35 +00001// -*- 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 Meenai492d7132017-10-09 19:25:17 +000017
Shoaib Meenai492d7132017-10-09 19:25:17 +000018extern "C" {
Peter Collingbourne4bdb80f2018-01-17 04:37:04 +000019typedef void (__cdecl* terminate_handler)();
20_LIBCPP_CRT_FUNC terminate_handler __cdecl set_terminate(
Shoaib Meenai492d7132017-10-09 19:25:17 +000021 terminate_handler _NewTerminateHandler) throw();
Peter Collingbourne4bdb80f2018-01-17 04:37:04 +000022_LIBCPP_CRT_FUNC terminate_handler __cdecl _get_terminate();
Shoaib Meenai492d7132017-10-09 19:25:17 +000023
Peter Collingbourne4bdb80f2018-01-17 04:37:04 +000024typedef void (__cdecl* unexpected_handler)();
25_LIBCPP_CRT_FUNC unexpected_handler __cdecl set_unexpected(
Shoaib Meenai492d7132017-10-09 19:25:17 +000026 unexpected_handler _NewUnexpectedHandler) throw();
Peter Collingbourne4bdb80f2018-01-17 04:37:04 +000027_LIBCPP_CRT_FUNC unexpected_handler __cdecl _get_unexpected();
Shoaib Meenai492d7132017-10-09 19:25:17 +000028
Peter Collingbourne4bdb80f2018-01-17 04:37:04 +000029_LIBCPP_CRT_FUNC int __cdecl __uncaught_exceptions();
Shoaib Meenai492d7132017-10-09 19:25:17 +000030}
Eric Fiselierd22c9dc2017-02-10 08:57:35 +000031
32namespace std {
33
Eric Fiselierd22c9dc2017-02-10 08:57:35 +000034unexpected_handler
35set_unexpected(unexpected_handler func) _NOEXCEPT {
36 return ::set_unexpected(func);
37}
38
39unexpected_handler get_unexpected() _NOEXCEPT {
40 return ::_get_unexpected();
41}
42
43_LIBCPP_NORETURN
44void unexpected() {
45 (*get_unexpected())();
46 // unexpected handler should not return
47 terminate();
48}
49
50terminate_handler set_terminate(terminate_handler func) _NOEXCEPT {
51 return ::set_terminate(func);
52}
53
54terminate_handler get_terminate() _NOEXCEPT {
55 return ::_get_terminate();
56}
57
58_LIBCPP_NORETURN
59void 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
80bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; }
81
82int uncaught_exceptions() _NOEXCEPT {
83 return __uncaught_exceptions();
84}
85
86bad_array_length::bad_array_length() _NOEXCEPT
87{
88}
89
90bad_array_length::~bad_array_length() _NOEXCEPT
91{
92}
93
94const char*
95bad_array_length::what() const _NOEXCEPT
96{
97 return "bad_array_length";
98}
99
Saleem Abdulrasoole7b38cd2017-09-15 05:42:39 +0000100bad_cast::bad_cast() _NOEXCEPT
101{
102}
103
104bad_cast::~bad_cast() _NOEXCEPT
105{
106}
107
108const char *
109bad_cast::what() const _NOEXCEPT
110{
111 return "std::bad_cast";
112}
113
114bad_typeid::bad_typeid() _NOEXCEPT
115{
116}
117
118bad_typeid::~bad_typeid() _NOEXCEPT
119{
120}
121
122const char *
123bad_typeid::what() const _NOEXCEPT
124{
125 return "std::bad_typeid";
126}
127
Shoaib Meenai492d7132017-10-09 19:25:17 +0000128#if defined(_LIBCPP_NO_VCRUNTIME)
129exception::~exception() _NOEXCEPT
130{
131}
132
133const char* exception::what() const _NOEXCEPT
134{
135 return "std::exception";
136}
137
138
139bad_exception::~bad_exception() _NOEXCEPT
140{
141}
142
143const char* bad_exception::what() const _NOEXCEPT
144{
145 return "std::bad_exception";
146}
147
148
149bad_alloc::bad_alloc() _NOEXCEPT
150{
151}
152
153bad_alloc::~bad_alloc() _NOEXCEPT
154{
155}
156
157const char*
158bad_alloc::what() const _NOEXCEPT
159{
160 return "std::bad_alloc";
161}
162
163bad_array_new_length::bad_array_new_length() _NOEXCEPT
164{
165}
166
167bad_array_new_length::~bad_array_new_length() _NOEXCEPT
168{
169}
170
171const char*
172bad_array_new_length::what() const _NOEXCEPT
173{
174 return "bad_array_new_length";
175}
176#endif // _LIBCPP_NO_VCRUNTIME
177
Eric Fiselierd22c9dc2017-02-10 08:57:35 +0000178} // namespace std