source: mainline/uspace/lib/cpp/include/__bits/exception.hpp@ e49d0ac

Last change on this file since e49d0ac was b57ba05, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago

Update headers in C++ files

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 * SPDX-FileCopyrightText: 2018 Jaroslav Jindrak
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef LIBCPP_BITS_EXCEPTION
8#define LIBCPP_BITS_EXCEPTION
9
10#include <__bits/trycatch.hpp>
11
12namespace std
13{
14 /**
15 * 18.8.1, class exception:
16 */
17
18 class exception
19 {
20 public:
21 exception() noexcept = default;
22 exception(const exception&) noexcept = default;
23 exception& operator=(const exception&) noexcept = default;
24 virtual ~exception() = default;
25
26 virtual const char* what() const noexcept;
27 };
28
29 /**
30 * 18.8.2, class bad_exception:
31 */
32
33 class bad_exception: public exception
34 {
35 public:
36 bad_exception() noexcept = default;
37 bad_exception(const bad_exception&) noexcept = default;
38 bad_exception& operator=(const bad_exception&) noexcept = default;
39
40 virtual const char* what() const noexcept;
41 };
42
43 /**
44 * 18.8.3, abnormal termination:
45 */
46
47 using terminate_handler = void (*)();
48
49 terminate_handler get_terminate() noexcept;
50 terminate_handler set_terminate(terminate_handler) noexcept;
51 [[noreturn]] void terminate() noexcept;
52
53 /**
54 * 18.8.4, uncaght_exceptions:
55 */
56
57 bool uncaught_exception() noexcept;
58 int uncaught_exceptions() noexcept;
59
60 using unexpected_handler = void (*)();
61
62 unexpected_handler get_unexpected() noexcept;
63 unexpected_handler set_unexpected(unexpected_handler) noexcept;
64 [[noreturn]] void unexpected();
65
66 /**
67 * 18.8.5, exception propagation:
68 */
69
70 namespace aux
71 {
72 class exception_ptr_t
73 { /* DUMMY BODY */ };
74 }
75
76 using exception_ptr = aux::exception_ptr_t;
77
78 exception_ptr current_exception() noexcept;
79 [[noreturn]] void rethrow_exception(exception_ptr);
80
81 template<class E>
82 exception_ptr make_exception_ptr(E e) noexcept
83 {
84 return exception_ptr{};
85 }
86
87 class nested_exception
88 {
89 public:
90 nested_exception() noexcept = default;
91 nested_exception(const nested_exception&) noexcept = default;
92 nested_exception& operator=(const nested_exception&) noexcept = default;
93 virtual ~nested_exception() = default;
94
95 [[noreturn]] void throw_nested() const;
96 exception_ptr nested_ptr() const noexcept;
97
98 private:
99 exception_ptr ptr_;
100 };
101
102 template<class E>
103 [[noreturn]] void throw_with_nested(E&& e)
104 {
105 terminate();
106 }
107
108 template<class E>
109 void rethrow_if_nested(const E& e)
110 {
111 auto casted = dynamic_cast<const nested_exception*>(&e);
112 if (casted)
113 casted->throw_nested();
114 }
115}
116
117#endif
118
Note: See TracBrowser for help on using the repository browser.