1 //===---------------------- system_error.cpp ------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #define _LIBCPP_BUILDING_SYSTEM_ERROR
11 #include "system_error"
15 _LIBCPP_BEGIN_NAMESPACE_STD
17 // class error_category
19 error_category::error_category() _NOEXCEPT
23 error_category::~error_category() _NOEXCEPT
28 error_category::default_error_condition(int ev
) const _NOEXCEPT
30 return error_condition(ev
, *this);
34 error_category::equivalent(int code
, const error_condition
& condition
) const _NOEXCEPT
36 return default_error_condition(code
) == condition
;
40 error_category::equivalent(const error_code
& code
, int condition
) const _NOEXCEPT
42 return *this == code
.category() && code
.value() == condition
;
46 __do_message::message(int ev
) const
48 return string(strerror(ev
));
51 class _LIBCPP_HIDDEN __generic_error_category
55 virtual const char* name() const _NOEXCEPT
;
56 virtual string
message(int ev
) const;
60 __generic_error_category::name() const _NOEXCEPT
66 __generic_error_category::message(int ev
) const
70 return string("unspecified generic_category error");
72 return __do_message::message(ev
);
76 generic_category() _NOEXCEPT
78 static __generic_error_category s
;
82 class _LIBCPP_HIDDEN __system_error_category
86 virtual const char* name() const _NOEXCEPT
;
87 virtual string
message(int ev
) const;
88 virtual error_condition
default_error_condition(int ev
) const _NOEXCEPT
;
92 __system_error_category::name() const _NOEXCEPT
98 __system_error_category::message(int ev
) const
102 return string("unspecified system_category error");
104 return __do_message::message(ev
);
108 __system_error_category::default_error_condition(int ev
) const _NOEXCEPT
112 return error_condition(ev
, system_category());
114 return error_condition(ev
, generic_category());
117 const error_category
&
118 system_category() _NOEXCEPT
120 static __system_error_category s
;
127 error_condition::message() const
129 return __cat_
->message(__val_
);
135 error_code::message() const
137 return __cat_
->message(__val_
);
143 system_error::__init(const error_code
& ec
, string what_arg
)
147 if (!what_arg
.empty())
149 what_arg
+= ec
.message();
151 return _VSTD::move(what_arg
);
154 system_error::system_error(error_code ec
, const string
& what_arg
)
155 : runtime_error(__init(ec
, what_arg
)),
160 system_error::system_error(error_code ec
, const char* what_arg
)
161 : runtime_error(__init(ec
, what_arg
)),
166 system_error::system_error(error_code ec
)
167 : runtime_error(__init(ec
, "")),
172 system_error::system_error(int ev
, const error_category
& ecat
, const string
& what_arg
)
173 : runtime_error(__init(error_code(ev
, ecat
), what_arg
)),
174 __ec_(error_code(ev
, ecat
))
178 system_error::system_error(int ev
, const error_category
& ecat
, const char* what_arg
)
179 : runtime_error(__init(error_code(ev
, ecat
), what_arg
)),
180 __ec_(error_code(ev
, ecat
))
184 system_error::system_error(int ev
, const error_category
& ecat
)
185 : runtime_error(__init(error_code(ev
, ecat
), "")),
186 __ec_(error_code(ev
, ecat
))
190 system_error::~system_error() _NOEXCEPT
195 __throw_system_error(int ev
, const char* what_arg
)
197 #ifndef _LIBCPP_NO_EXCEPTIONS
198 throw system_error(error_code(ev
, system_category()), what_arg
);
205 _LIBCPP_END_NAMESPACE_STD