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 //===----------------------------------------------------------------------===//
12 #define _LIBCPP_BUILDING_SYSTEM_ERROR
13 #include "system_error"
15 #include "include/config_elast.h"
19 _LIBCPP_BEGIN_NAMESPACE_STD
21 // class error_category
23 error_category::error_category() _NOEXCEPT
27 error_category::~error_category() _NOEXCEPT
32 error_category::default_error_condition(int ev
) const _NOEXCEPT
34 return error_condition(ev
, *this);
38 error_category::equivalent(int code
, const error_condition
& condition
) const _NOEXCEPT
40 return default_error_condition(code
) == condition
;
44 error_category::equivalent(const error_code
& code
, int condition
) const _NOEXCEPT
46 return *this == code
.category() && code
.value() == condition
;
50 __do_message::message(int ev
) const
52 return string(strerror(ev
));
55 class _LIBCPP_HIDDEN __generic_error_category
59 virtual const char* name() const _NOEXCEPT
;
60 virtual string
message(int ev
) const;
64 __generic_error_category::name() const _NOEXCEPT
70 __generic_error_category::message(int ev
) const
73 if (ev
> _LIBCPP_ELAST
)
74 return string("unspecified generic_category error");
75 #endif // _LIBCPP_ELAST
76 return __do_message::message(ev
);
80 generic_category() _NOEXCEPT
82 static __generic_error_category s
;
86 class _LIBCPP_HIDDEN __system_error_category
90 virtual const char* name() const _NOEXCEPT
;
91 virtual string
message(int ev
) const;
92 virtual error_condition
default_error_condition(int ev
) const _NOEXCEPT
;
96 __system_error_category::name() const _NOEXCEPT
102 __system_error_category::message(int ev
) const
105 if (ev
> _LIBCPP_ELAST
)
106 return string("unspecified system_category error");
107 #endif // _LIBCPP_ELAST
108 return __do_message::message(ev
);
112 __system_error_category::default_error_condition(int ev
) const _NOEXCEPT
115 if (ev
> _LIBCPP_ELAST
)
116 return error_condition(ev
, system_category());
117 #endif // _LIBCPP_ELAST
118 return error_condition(ev
, generic_category());
121 const error_category
&
122 system_category() _NOEXCEPT
124 static __system_error_category s
;
131 error_condition::message() const
133 return __cat_
->message(__val_
);
139 error_code::message() const
141 return __cat_
->message(__val_
);
147 system_error::__init(const error_code
& ec
, string what_arg
)
151 if (!what_arg
.empty())
153 what_arg
+= ec
.message();
158 system_error::system_error(error_code ec
, const string
& what_arg
)
159 : runtime_error(__init(ec
, what_arg
)),
164 system_error::system_error(error_code ec
, const char* what_arg
)
165 : runtime_error(__init(ec
, what_arg
)),
170 system_error::system_error(error_code ec
)
171 : runtime_error(__init(ec
, "")),
176 system_error::system_error(int ev
, const error_category
& ecat
, const string
& what_arg
)
177 : runtime_error(__init(error_code(ev
, ecat
), what_arg
)),
178 __ec_(error_code(ev
, ecat
))
182 system_error::system_error(int ev
, const error_category
& ecat
, const char* what_arg
)
183 : runtime_error(__init(error_code(ev
, ecat
), what_arg
)),
184 __ec_(error_code(ev
, ecat
))
188 system_error::system_error(int ev
, const error_category
& ecat
)
189 : runtime_error(__init(error_code(ev
, ecat
), "")),
190 __ec_(error_code(ev
, ecat
))
194 system_error::~system_error() _NOEXCEPT
199 __throw_system_error(int ev
, const char* what_arg
)
201 #ifndef _LIBCPP_NO_EXCEPTIONS
202 throw system_error(error_code(ev
, system_category()), what_arg
);
209 _LIBCPP_END_NAMESPACE_STD