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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 10d65d70 was b57a3ee, checked in by Dzejrou <dzejrou@…>, 7 years ago

cpp: refactored the library layout, everything from the impl directory was moved to the bits directory for the sake of consistency, updated copyright notices and include guards

  • Property mode set to 100644
File size: 4.0 KB
RevLine 
[b1cd380c]1/*
[74b03e3]2 * Copyright (c) 2018 Jaroslav Jindrak
[b1cd380c]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
[b57a3ee]29#ifndef LIBCPP_BITS_EXCEPTION
30#define LIBCPP_BITS_EXCEPTION
[b1cd380c]31
[7bbf91e]32#include <__bits/trycatch.hpp>
[1610aa35]33
[b1cd380c]34namespace std
35{
[1610aa35]36 /**
37 * 18.8.1, class exception:
38 */
[b1cd380c]39
[9396c52]40 class exception
41 {
42 public:
[1610aa35]43 exception() noexcept = default;
44 exception(const exception&) noexcept = default;
45 exception& operator=(const exception&) noexcept = default;
[9396c52]46 virtual ~exception() = default;
[74b03e3]47
[1610aa35]48 virtual const char* what() const noexcept;
[9396c52]49 };
[1610aa35]50
51 /**
52 * 18.8.2, class bad_exception:
53 */
54
55 class bad_exception: public exception
56 {
57 public:
58 bad_exception() noexcept = default;
59 bad_exception(const bad_exception&) noexcept = default;
60 bad_exception& operator=(const bad_exception&) noexcept = default;
61
62 virtual const char* what() const noexcept;
63 };
64
65 /**
66 * 18.8.3, abnormal termination:
67 */
68
69 using terminate_handler = void (*)();
70
71 terminate_handler get_terminate() noexcept;
72 terminate_handler set_terminate(terminate_handler) noexcept;
73 [[noreturn]] void terminate() noexcept;
74
75 /**
76 * 18.8.4, uncaght_exceptions:
77 */
78
79 bool uncaught_exception() noexcept;
80 int uncaught_exceptions() noexcept;
81
82 using unexpected_handler = void (*)();
83
84 unexpected_handler get_unexpected() noexcept;
85 unexpected_handler set_unexpected(unexpected_handler) noexcept;
86 [[noreturn]] void unexpected();
87
88 /**
89 * 18.8.5, exception propagation:
90 */
91
92 namespace aux
93 {
94 class exception_ptr_t
95 { /* DUMMY BODY */ };
96 }
97
98 using exception_ptr = aux::exception_ptr_t;
99
100 exception_ptr current_exception() noexcept;
101 [[noreturn]] void rethrow_exception(exception_ptr);
102
103 template<class E>
104 exception_ptr make_exception_ptr(E e) noexcept
105 {
106 return exception_ptr{};
107 }
108
109 class nested_exception
110 {
111 public:
112 nested_exception() noexcept = default;
113 nested_exception(const nested_exception&) noexcept = default;
114 nested_exception& operator=(const nested_exception&) noexcept = default;
115 virtual ~nested_exception() = default;
116
117 [[noreturn]] void throw_nested() const;
118 exception_ptr nested_ptr() const noexcept;
119
120 private:
121 exception_ptr ptr_;
122 };
123
124 template<class E>
125 [[noreturn]] void throw_with_nested(E&& e)
126 {
127 terminate();
128 }
129
130 template<class E>
131 void rethrow_if_nested(const E& e)
132 {
133 auto casted = dynamic_cast<const nested_exception*>(&e);
134 if (casted)
135 casted->throw_nested();
136 }
[b1cd380c]137}
138
139#endif
140
Note: See TracBrowser for help on using the repository browser.