blob: 7315b8261b768ff603df183ce55c82b6ab653fb3 [file] [log] [blame]
Eric Fiselierd22c9dc2017-02-10 08:57:35 +00001// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
Chandler Carruth57b08b02019-01-19 10:56:40 +00004// 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
Eric Fiselierd22c9dc2017-02-10 08:57:35 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_ABI_MICROSOFT
11#error this header can only be used when targeting the MSVC ABI
12#endif
13
14#include <stdio.h>
15#include <stdlib.h>
Shoaib Meenai492d7132017-10-09 19:25:17 +000016
Shoaib Meenai492d7132017-10-09 19:25:17 +000017extern "C" {
Peter Collingbourne4bdb80f2018-01-17 04:37:04 +000018typedef void (__cdecl* terminate_handler)();
19_LIBCPP_CRT_FUNC terminate_handler __cdecl set_terminate(
Shoaib Meenai492d7132017-10-09 19:25:17 +000020 terminate_handler _NewTerminateHandler) throw();
Peter Collingbourne4bdb80f2018-01-17 04:37:04 +000021_LIBCPP_CRT_FUNC terminate_handler __cdecl _get_terminate();
Shoaib Meenai492d7132017-10-09 19:25:17 +000022
Peter Collingbourne4bdb80f2018-01-17 04:37:04 +000023typedef void (__cdecl* unexpected_handler)();
Peter Collingbourne5e27cce2018-01-18 00:33:35 +000024unexpected_handler __cdecl set_unexpected(
Shoaib Meenai492d7132017-10-09 19:25:17 +000025 unexpected_handler _NewUnexpectedHandler) throw();
Peter Collingbourne5e27cce2018-01-18 00:33:35 +000026unexpected_handler __cdecl _get_unexpected();
Shoaib Meenai492d7132017-10-09 19:25:17 +000027
Peter Collingbourne5e27cce2018-01-18 00:33:35 +000028int __cdecl __uncaught_exceptions();
Shoaib Meenai492d7132017-10-09 19:25:17 +000029}
Eric Fiselierd22c9dc2017-02-10 08:57:35 +000030
31namespace std {
32
Eric Fiselierd22c9dc2017-02-10 08:57:35 +000033unexpected_handler
34set_unexpected(unexpected_handler func) _NOEXCEPT {
35 return ::set_unexpected(func);
36}
37
38unexpected_handler get_unexpected() _NOEXCEPT {
39 return ::_get_unexpected();
40}
41
42_LIBCPP_NORETURN
43void unexpected() {
44 (*get_unexpected())();
45 // unexpected handler should not return
46 terminate();
47}
48
49terminate_handler set_terminate(terminate_handler func) _NOEXCEPT {
50 return ::set_terminate(func);
51}
52
53terminate_handler get_terminate() _NOEXCEPT {
54 return ::_get_terminate();
55}
56
57_LIBCPP_NORETURN
58void terminate() _NOEXCEPT
59{
60#ifndef _LIBCPP_NO_EXCEPTIONS
61 try
62 {
63#endif // _LIBCPP_NO_EXCEPTIONS
64 (*get_terminate())();
65 // handler should not return
66 fprintf(stderr, "terminate_handler unexpectedly returned\n");
67 ::abort();
68#ifndef _LIBCPP_NO_EXCEPTIONS
69 }
70 catch (...)
71 {
72 // handler should not throw exception
73 fprintf(stderr, "terminate_handler unexpectedly threw an exception\n");
74 ::abort();
75 }
76#endif // _LIBCPP_NO_EXCEPTIONS
77}
78
79bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; }
80
81int uncaught_exceptions() _NOEXCEPT {
82 return __uncaught_exceptions();
83}
84
Eric Fiseliere69290d2019-03-05 01:57:01 +000085#if !defined(_LIBCPP_ABI_VCRUNTIME)
Saleem Abdulrasoole7b38cd2017-09-15 05:42:39 +000086bad_cast::bad_cast() _NOEXCEPT
87{
88}
89
90bad_cast::~bad_cast() _NOEXCEPT
91{
92}
93
94const char *
95bad_cast::what() const _NOEXCEPT
96{
97 return "std::bad_cast";
98}
99
100bad_typeid::bad_typeid() _NOEXCEPT
101{
102}
103
104bad_typeid::~bad_typeid() _NOEXCEPT
105{
106}
107
108const char *
109bad_typeid::what() const _NOEXCEPT
110{
111 return "std::bad_typeid";
112}
113
Shoaib Meenai492d7132017-10-09 19:25:17 +0000114exception::~exception() _NOEXCEPT
115{
116}
117
118const char* exception::what() const _NOEXCEPT
119{
120 return "std::exception";
121}
122
123
124bad_exception::~bad_exception() _NOEXCEPT
125{
126}
127
128const char* bad_exception::what() const _NOEXCEPT
129{
130 return "std::bad_exception";
131}
132
133
134bad_alloc::bad_alloc() _NOEXCEPT
135{
136}
137
138bad_alloc::~bad_alloc() _NOEXCEPT
139{
140}
141
142const char*
143bad_alloc::what() const _NOEXCEPT
144{
145 return "std::bad_alloc";
146}
147
148bad_array_new_length::bad_array_new_length() _NOEXCEPT
149{
150}
151
152bad_array_new_length::~bad_array_new_length() _NOEXCEPT
153{
154}
155
156const char*
157bad_array_new_length::what() const _NOEXCEPT
158{
159 return "bad_array_new_length";
160}
Eric Fiseliere69290d2019-03-05 01:57:01 +0000161#endif // !_LIBCPP_ABI_VCRUNTIME
Shoaib Meenai492d7132017-10-09 19:25:17 +0000162
Eric Fiselierd22c9dc2017-02-10 08:57:35 +0000163} // namespace std