]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - src/support/runtime/exception_msvc.ipp
Vendor import of libc++ trunk r300422:
[FreeBSD/FreeBSD.git] / src / support / runtime / exception_msvc.ipp
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
89 } // namespace std