Debian Codegraph @

libcxx/src/support/runtime/exception_msvc.ipp

raw
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // 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
7 //
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>
16
17 extern "C" {
18 typedef void(__cdecl* terminate_handler)();
19 _LIBCPP_CRT_FUNC terminate_handler __cdecl set_terminate(terminate_handler _NewTerminateHandler) throw();
20 _LIBCPP_CRT_FUNC terminate_handler __cdecl _get_terminate();
21
22 typedef void(__cdecl* unexpected_handler)();
23 unexpected_handler __cdecl set_unexpected(unexpected_handler _NewUnexpectedHandler) throw();
24 unexpected_handler __cdecl _get_unexpected();
25
26 int __cdecl __uncaught_exceptions();
27 }
28
29 namespace std {
30
31 unexpected_handler set_unexpected(unexpected_handler func) noexcept { return ::set_unexpected(func); }
32
33 unexpected_handler get_unexpected() noexcept { return ::_get_unexpected(); }
34
35 _LIBCPP_NORETURN void unexpected() {
36 (*get_unexpected())();
37 // unexpected handler should not return
38 terminate();
39 }
40
41 terminate_handler set_terminate(terminate_handler func) noexcept { return ::set_terminate(func); }
42
43 terminate_handler get_terminate() noexcept { return ::_get_terminate(); }
44
45 _LIBCPP_NORETURN void terminate() noexcept {
46 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
47 try {
48 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
49 (*get_terminate())();
50 // handler should not return
51 fprintf(stderr, "terminate_handler unexpectedly returned\n");
52 ::abort();
53 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
54 } catch (...) {
55 // handler should not throw exception
56 fprintf(stderr, "terminate_handler unexpectedly threw an exception\n");
57 ::abort();
58 }
59 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
60 }
61
62 bool uncaught_exception() noexcept { return uncaught_exceptions() > 0; }
63
64 int uncaught_exceptions() noexcept { return __uncaught_exceptions(); }
65
66 #if !defined(_LIBCPP_ABI_VCRUNTIME)
67 bad_cast::bad_cast() noexcept {}
68
69 bad_cast::~bad_cast() noexcept {}
70
71 const char* bad_cast::what() const noexcept { return "std::bad_cast"; }
72
73 bad_typeid::bad_typeid() noexcept {}
74
75 bad_typeid::~bad_typeid() noexcept {}
76
77 const char* bad_typeid::what() const noexcept { return "std::bad_typeid"; }
78
79 exception::~exception() noexcept {}
80
81 const char* exception::what() const noexcept { return "std::exception"; }
82
83 bad_exception::~bad_exception() noexcept {}
84
85 const char* bad_exception::what() const noexcept { return "std::bad_exception"; }
86
87 bad_alloc::bad_alloc() noexcept {}
88
89 bad_alloc::~bad_alloc() noexcept {}
90
91 const char* bad_alloc::what() const noexcept { return "std::bad_alloc"; }
92
93 bad_array_new_length::bad_array_new_length() noexcept {}
94
95 bad_array_new_length::~bad_array_new_length() noexcept {}
96
97 const char* bad_array_new_length::what() const noexcept { return "bad_array_new_length"; }
98 #endif // !_LIBCPP_ABI_VCRUNTIME
99
100 } // namespace std