@@ -31,6 +31,8 @@ namespace mrdox {
31
31
// Error
32
32
//
33
33
34
+ class Exception ;
35
+
34
36
/* * Holds the description of an error, or success.
35
37
*/
36
38
class [[nodiscard]] MRDOX_DECL
@@ -161,15 +163,28 @@ class [[nodiscard]] MRDOX_DECL
161
163
return message_ == rhs.message_ ;
162
164
}
163
165
164
- #if 0
165
166
/* * Return a null-terminated error string.
166
167
*/
167
168
char const *
168
- what() const noexcept override
169
+ what () const noexcept
169
170
{
170
171
return reason_.c_str ();
171
172
}
172
- #endif
173
+
174
+ /* * Throw Exception(*this)
175
+
176
+ @pre this->failed()
177
+ */
178
+ void Throw () const ;
179
+
180
+ /* * Throw Exception(*this), or do nothing if no failure.
181
+ */
182
+ void maybeThrow () const
183
+ {
184
+ if (! failed ())
185
+ return ;
186
+ Throw ();
187
+ }
173
188
174
189
constexpr void swap (Error& rhs) noexcept
175
190
{
@@ -190,10 +205,51 @@ class [[nodiscard]] MRDOX_DECL
190
205
static Error success () noexcept ;
191
206
};
192
207
208
+ // ------------------------------------------------
209
+ //
210
+ // Exception
211
+ //
212
+ // ------------------------------------------------
213
+
214
+ /* * Type of all exceptions thrown by the API.
215
+ */
216
+ class MRDOX_DECL
217
+ Exception final : public std::exception
218
+ {
219
+ Error err_;
220
+
221
+ public:
222
+ /* * Constructor.
223
+ */
224
+ explicit
225
+ Exception (
226
+ Error err) noexcept
227
+ : err_(std::move(err))
228
+ {
229
+ }
230
+
231
+ /* * Return the Error stored in the exception.
232
+ */
233
+ Error const &
234
+ error () const noexcept
235
+ {
236
+ return err_;
237
+ }
238
+
239
+ /* * Return a null-terminated error string.
240
+ */
241
+ char const *
242
+ what () const noexcept override
243
+ {
244
+ return err_.what ();
245
+ }
246
+ };
247
+
193
248
// ------------------------------------------------
194
249
//
195
250
// Expected
196
251
//
252
+ // ------------------------------------------------
197
253
198
254
/* * A container holding an error or a value.
199
255
*/
0 commit comments