• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
18extern "C" {
19typedef 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
24typedef void (__cdecl* unexpected_handler)();
25unexpected_handler __cdecl set_unexpected(
26    unexpected_handler _NewUnexpectedHandler) throw();
27unexpected_handler __cdecl _get_unexpected();
28
29int __cdecl __uncaught_exceptions();
30}
31
32namespace std {
33
34unexpected_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
86#if defined(_LIBCPP_NO_VCRUNTIME)
87bad_cast::bad_cast() _NOEXCEPT
88{
89}
90
91bad_cast::~bad_cast() _NOEXCEPT
92{
93}
94
95const char *
96bad_cast::what() const _NOEXCEPT
97{
98  return "std::bad_cast";
99}
100
101bad_typeid::bad_typeid() _NOEXCEPT
102{
103}
104
105bad_typeid::~bad_typeid() _NOEXCEPT
106{
107}
108
109const char *
110bad_typeid::what() const _NOEXCEPT
111{
112  return "std::bad_typeid";
113}
114
115exception::~exception() _NOEXCEPT
116{
117}
118
119const char* exception::what() const _NOEXCEPT
120{
121  return "std::exception";
122}
123
124
125bad_exception::~bad_exception() _NOEXCEPT
126{
127}
128
129const char* bad_exception::what() const _NOEXCEPT
130{
131  return "std::bad_exception";
132}
133
134
135bad_alloc::bad_alloc() _NOEXCEPT
136{
137}
138
139bad_alloc::~bad_alloc() _NOEXCEPT
140{
141}
142
143const char*
144bad_alloc::what() const _NOEXCEPT
145{
146    return "std::bad_alloc";
147}
148
149bad_array_new_length::bad_array_new_length() _NOEXCEPT
150{
151}
152
153bad_array_new_length::~bad_array_new_length() _NOEXCEPT
154{
155}
156
157const char*
158bad_array_new_length::what() const _NOEXCEPT
159{
160    return "bad_array_new_length";
161}
162#endif // _LIBCPP_NO_VCRUNTIME
163
164} // namespace std
165