-
Notifications
You must be signed in to change notification settings - Fork 50
/
error_types.hpp
324 lines (243 loc) · 8.56 KB
/
error_types.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
//
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/boostorg/url
//
#ifndef BOOST_URL_ERROR_TYPES_HPP
#define BOOST_URL_ERROR_TYPES_HPP
#include <boost/url/detail/config.hpp>
#include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp>
#include <boost/system/result.hpp>
namespace boost {
namespace urls {
#ifndef BOOST_URL_DOCS
namespace error_types {
#endif
/** The type of error category used by the library
@warning This alias is no longer supported and
should not be used in new code. Please use
`system::error_category` instead.
This alias is included for backwards
compatibility with earlier versions of the
library.
However, it will be removed in future releases,
and using it in new code is not recommended.
Please use the updated version instead to
ensure compatibility with future versions of
the library.
*/
using error_category
BOOST_URL_DEPRECATED("Use system::error_category instead") =
boost::system::error_category;
/** The type of error code used by the library
@warning This alias is no longer supported and
should not be used in new code. Please use
`system::error_code` instead.
This alias is included for backwards
compatibility with earlier versions of the
library.
However, it will be removed in future releases,
and using it in new code is not recommended.
Please use the updated version instead to
ensure compatibility with future versions of
the library.
*/
using error_code
BOOST_URL_DEPRECATED("Use system::error_code instead") =
boost::system::error_code;
/** The type of error condition used by the library
@warning This alias is no longer supported and
should not be used in new code. Please use
`system::error_condition` instead.
This alias is included for backwards
compatibility with earlier versions of the
library.
However, it will be removed in future releases,
and using it in new code is not recommended.
Please use the updated version instead to
ensure compatibility with future versions of
the library.
*/
using error_condition
BOOST_URL_DEPRECATED("Use system::error_condition instead") =
boost::system::error_condition;
/** The type of system error thrown by the library
@warning This alias is no longer supported and
should not be used in new code. Please use
`system::system_error` instead.
This alias is included for backwards
compatibility with earlier versions of the
library.
However, it will be removed in future releases,
and using it in new code is not recommended.
Please use the updated version instead to
ensure compatibility with future versions of
the library.
*/
using system_error
BOOST_URL_DEPRECATED("Use system::system_error instead") =
boost::system::system_error;
/** A function to return the generic error category used by the library
@warning This alias is no longer supported and
should not be used in new code. Please use
`core::string_view` instead.
This alias is included for backwards
compatibility with earlier versions of the
library.
However, it will be removed in future releases,
and using it in new code is not recommended.
Please use the updated version instead to
ensure compatibility with future versions of
the library.
*/
#ifdef BOOST_URL_DOCS
error_category const& generic_category();
#else
/** A function to return the generic error category used by the library
@warning This alias is no longer supported and
should not be used in new code. Please use
`core::string_view` instead.
This alias is included for backwards
compatibility with earlier versions of the
library.
However, it will be removed in future releases,
and using it in new code is not recommended.
Please use the updated version instead to
ensure compatibility with future versions of
the library.
*/
using boost::system::generic_category;
#endif
/** A function to return the system error category used by the library
@warning This alias is no longer supported and
should not be used in new code. Please use
`core::string_view` instead.
This alias is included for backwards
compatibility with earlier versions of the
library.
However, it will be removed in future releases,
and using it in new code is not recommended.
Please use the updated version instead to
ensure compatibility with future versions of
the library.
*/
#ifdef BOOST_URL_DOCS
error_category const& system_category();
#else
/** A function to return the system error category used by the library
@warning This alias is no longer supported and
should not be used in new code. Please use
`core::string_view` instead.
This alias is included for backwards
compatibility with earlier versions of the
library.
However, it will be removed in future releases,
and using it in new code is not recommended.
Please use the updated version instead to
ensure compatibility with future versions of
the library.
*/
using boost::system::system_category;
#endif
/** The set of constants used for cross-platform error codes
@warning This alias is no longer supported and
should not be used in new code. Please use
`core::string_view` instead.
This alias is included for backwards
compatibility with earlier versions of the
library.
However, it will be removed in future releases,
and using it in new code is not recommended.
Please use the updated version instead to
ensure compatibility with future versions of
the library.
*/
namespace errc = boost::system::errc;
/** The type of result returned by library functions
@warning This alias is no longer supported and
should not be used in new code. Please use
`system::result` instead.
This alias is included for backwards
compatibility with earlier versions of the
library.
However, it will be removed in future releases,
and using it in new code is not recommended.
Please use the updated version instead to
ensure compatibility with future versions of
the library.
@details This is an alias template used as the return type
for functions that can either return a container,
or fail with an error code. This is a brief
synopsis of the type:
@par Declaration
@code
template< class T >
class result
{
public:
//
// Return true if the result contains an error
//
constexpr bool has_error() const noexcept;
//
// Return the error
//
constexpr system::error_code error() const noexcept;
//
// Return true if the result contains a value
//
constexpr bool has_value() const noexcept;
constexpr explicit operator bool() const noexcept;
//
// Return the value, or throw an exception
//
constexpr T& value();
constexpr T const& value() const;
// Return the value.
// Precondition: has_value()==true
//
constexpr T& operator*() noexcept;
constexpr T* operator->() noexcept;
constexpr T const& operator*() const noexcept;
constexpr T const* operator->() const noexcept;
...more
@endcode
@par Usage
Given the function @ref parse_uri with this signature:
@code
system::result< url_view > parse_uri( core::string_view s ) noexcept;
@endcode
The following statement captures the value in a
variable upon success, otherwise throws:
@code
url_view u = parse_uri( "http://example.com/path/to/file.txt" ).value();
@endcode
This statement captures the result in a local
variable and inspects the error condition:
@code
system::result< url_view > rv = parse_uri( "http://example.com/path/to/file.txt" );
if(! rv )
std::cout << rv.error();
else
std::cout << *rv;
@endcode
@tparam T The type of value held by the result.
@see
@li <a href="https://boost.org/libs/system/doc/html/system.html#ref_resultt_e"
>`boost::system::result`</a>
*/
template<class T>
using result
BOOST_URL_DEPRECATED("Use system::result<T> instead") =
boost::system::result<T, system::error_code>;
#ifndef BOOST_URL_DOCS
} // error_types
using namespace error_types;
#endif
} // urls
} // boost
#endif