1
A ti(std::system_error) can be thrown when an error occurs that has an
2
associated error code. Such errors are typically encountered when calling
3
low-level (like operating system) functions.
5
Before using tt(system_error) the tthi(system_error) header file must have
8
A tt(system_error) object can be constructed using the standard textual
9
description of the nature of the encountered error, but in addition accepts an
10
emi(error_code) or emi(error_category) object (see the next two sections),
11
further specifying the nature of the error. The tt(error_code) and
12
tt(error_category) classes are also declared in the tt(system_error) header
15
The header file tt(system_error) also defines an ti(enum class errc)hi(errc)
16
whose values are equal to and describe in a less cryptic way the traditional
17
error code values as offered by bf(C) macros, e.g.,
21
address_family_not_supported, // EAFNOSUPPORT
22
address_in_use, // EADDRINUSE
23
address_not_available, // EADDRNOTAVAIL
24
already_connected, // EISCONN
25
argument_list_too_long, // E2BIG
26
argument_out_of_domain, // EDOM
27
bad_address, // EFAULT
32
In addition to the standard tt(what) member, the tt(system_error) class also
33
offers a member tt(code) returning a const reference to the exception's error
34
code. Here is the class's public interface:
36
class system_error: public runtime_error
39
system_error(error_code ec, string const &what_arg);
40
system_error(error_code ec, char const *what_arg);
41
system_error(error_code ec);
42
system_error(int ev, error_category const &ecat,
43
string const &what_arg);
44
system_error(int ev, error_category const &ecat,
45
char const *what_arg);
46
system_error(int ev, error_category const &ecat);
47
error_code const &code() const noexcept;
48
char const *what() const noexcept;
52
The NTBS returned by its tt(what) member may be formatted by a
53
tt(system_error) object like this:
55
what_arg + ": " + code().message()
58
Note that, although tt(system_error) was derived from tt(runtime_error),
59
you'll lose the tt(code) member when catching a tt(std::exception) object. Of
60
course, downcasting is always possible, but that's a stopgap. Therefore, if a
61
tt(system_error) is thrown, a matching tt(catch(system_error const &)) clause
62
should be provided (for a flexible alternative, see the class
63
hi(Exception (Bobcat)) tt(FBB::Exception) in the author's
64
url(Bobcat library)(http://bobcat.sourceforge.net).\
65
hi(Bobcat library)hi(http://bobcat.sourceforge.net))