source: mainline/uspace/lib/cpp/src/stdexcept.cpp@ 6404aca

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

cpp: added <stdexcept>

  • Property mode set to 100644
File size: 5.3 KB
Line 
1/*
2 * Copyright (c) 2018 Jaroslav Jindrak
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
29#include <cstdlib>
30#include <cstring>
31#include <stdexcept>
32#include <string>
33
34namespace std
35{
36 logic_error::logic_error(const string& what)
37 : what_{hel::str_dup(what.c_str())}
38 { /* DUMMY BODY */ }
39
40 logic_error::logic_error(const char* what)
41 : what_{hel::str_dup(what)}
42 { /* DUMMY BODY */ }
43
44 logic_error::logic_error(const logic_error& other) noexcept
45 : exception{other}, what_{hel::str_dup(other.what_)}
46 { /* DUMMY BODY */ }
47
48 logic_error& logic_error::operator=(const logic_error& other)
49 {
50 if (what_)
51 free(what_);
52 what_ = hel::str_dup(other.what_);
53
54 return *this;
55 }
56
57 logic_error::~logic_error()
58 {
59 free(what_);
60 }
61
62 const char* logic_error::what() const noexcept
63 {
64 return what_;
65 }
66
67 domain_error::domain_error(const string& what)
68 : logic_error{what}
69 { /* DUMMY BODY */ }
70
71 domain_error::domain_error(const char* what)
72 : logic_error{what}
73 { /* DUMMY BODY */ }
74
75 domain_error::domain_error(const domain_error& other) noexcept
76 : logic_error{other}
77 { /* DUMMY BODY */ }
78
79 invalid_argument::invalid_argument(const string& what)
80 : logic_error{what}
81 { /* DUMMY BODY */ }
82
83 invalid_argument::invalid_argument(const char* what)
84 : logic_error{what}
85 { /* DUMMY BODY */ }
86
87 invalid_argument::invalid_argument(const invalid_argument& other) noexcept
88 : logic_error{other}
89 { /* DUMMY BODY */ }
90
91 length_error::length_error(const string& what)
92 : logic_error{what}
93 { /* DUMMY BODY */ }
94
95 length_error::length_error(const char* what)
96 : logic_error{what}
97 { /* DUMMY BODY */ }
98
99 length_error::length_error(const length_error& other) noexcept
100 : logic_error{other}
101 { /* DUMMY BODY */ }
102
103 out_of_range::out_of_range(const string& what)
104 : logic_error{what}
105 { /* DUMMY BODY */ }
106
107 out_of_range::out_of_range(const char* what)
108 : logic_error{what}
109 { /* DUMMY BODY */ }
110
111 out_of_range::out_of_range(const out_of_range& other) noexcept
112 : logic_error{other}
113 { /* DUMMY BODY */ }
114
115 runtime_error::runtime_error(const string& what)
116 : what_{hel::str_dup(what.c_str())}
117 { /* DUMMY BODY */ }
118
119 runtime_error::runtime_error(const char* what)
120 : what_{hel::str_dup(what)}
121 { /* DUMMY BODY */ }
122
123 runtime_error::runtime_error(const runtime_error& other) noexcept
124 : exception{other}, what_{hel::str_dup(other.what_)}
125 { /* DUMMY BODY */ }
126
127 runtime_error& runtime_error::operator=(const runtime_error& other)
128 {
129 if (what_)
130 free(what_);
131 what_ = hel::str_dup(other.what_);
132
133 return *this;
134 }
135
136 runtime_error::~runtime_error()
137 {
138 free(what_);
139 }
140
141 const char* runtime_error::what() const noexcept
142 {
143 return what_;
144 }
145
146 range_error::range_error(const string& what)
147 : runtime_error{what}
148 { /* DUMMY BODY */ }
149
150 range_error::range_error(const char* what)
151 : runtime_error{what}
152 { /* DUMMY BODY */ }
153
154 range_error::range_error(const range_error& other) noexcept
155 : runtime_error{other}
156 { /* DUMMY BODY */ }
157
158 overflow_error::overflow_error(const string& what)
159 : runtime_error{what}
160 { /* DUMMY BODY */ }
161
162 overflow_error::overflow_error(const char* what)
163 : runtime_error{what}
164 { /* DUMMY BODY */ }
165
166 overflow_error::overflow_error(const overflow_error& other) noexcept
167 : runtime_error{other}
168 { /* DUMMY BODY */ }
169
170 underflow_error::underflow_error(const string& what)
171 : runtime_error{what}
172 { /* DUMMY BODY */ }
173
174 underflow_error::underflow_error(const char* what)
175 : runtime_error{what}
176 { /* DUMMY BODY */ }
177
178 underflow_error::underflow_error(const underflow_error& other) noexcept
179 : runtime_error{other}
180 { /* DUMMY BODY */ }
181}
Note: See TracBrowser for help on using the repository browser.