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
12 #include "system_error"
16 _LIBCPP_BEGIN_NAMESPACE_STD
18 // class error_category
20 error_category::error_category() _NOEXCEPT
24 error_category::~error_category() _NOEXCEPT
29 error_category::default_error_condition(int ev) const _NOEXCEPT
31 return error_condition(ev, *this);
35 error_category::equivalent(int code, const error_condition& condition) const _NOEXCEPT
37 return default_error_condition(code) == condition;
41 error_category::equivalent(const error_code& code, int condition) const _NOEXCEPT
43 return *this == code.category() && code.value() == condition;
47 __do_message::message(int ev) const
49 return string(strerror(ev));
52 class _LIBCPP_HIDDEN __generic_error_category
56 virtual const char* name() const _NOEXCEPT;
57 virtual string message(int ev) const;
61 __generic_error_category::name() const _NOEXCEPT
67 __generic_error_category::message(int ev) const
70 if (ev > _LIBCPP_ELAST)
71 return string("unspecified generic_category error");
72 #endif // _LIBCPP_ELAST
73 return __do_message::message(ev);
77 generic_category() _NOEXCEPT
79 static __generic_error_category s;
83 class _LIBCPP_HIDDEN __system_error_category
87 virtual const char* name() const _NOEXCEPT;
88 virtual string message(int ev) const;
89 virtual error_condition default_error_condition(int ev) const _NOEXCEPT;
93 __system_error_category::name() const _NOEXCEPT
99 __system_error_category::message(int ev) const
102 if (ev > _LIBCPP_ELAST)
103 return string("unspecified system_category error");
104 #endif // _LIBCPP_ELAST
105 return __do_message::message(ev);
109 __system_error_category::default_error_condition(int ev) const _NOEXCEPT
112 if (ev > _LIBCPP_ELAST)
113 return error_condition(ev, system_category());
114 #endif // _LIBCPP_ELAST
115 return error_condition(ev, generic_category());
118 const error_category&
119 system_category() _NOEXCEPT
121 static __system_error_category s;
128 error_condition::message() const
130 return __cat_->message(__val_);
136 error_code::message() const
138 return __cat_->message(__val_);
144 system_error::__init(const error_code& ec, string what_arg)
148 if (!what_arg.empty())
150 what_arg += ec.message();
152 return _VSTD::move(what_arg);
155 system_error::system_error(error_code ec, const string& what_arg)
156 : runtime_error(__init(ec, what_arg)),
161 system_error::system_error(error_code ec, const char* what_arg)
162 : runtime_error(__init(ec, what_arg)),
167 system_error::system_error(error_code ec)
168 : runtime_error(__init(ec, "")),
173 system_error::system_error(int ev, const error_category& ecat, const string& what_arg)
174 : runtime_error(__init(error_code(ev, ecat), what_arg)),
175 __ec_(error_code(ev, ecat))
179 system_error::system_error(int ev, const error_category& ecat, const char* what_arg)
180 : runtime_error(__init(error_code(ev, ecat), what_arg)),
181 __ec_(error_code(ev, ecat))
185 system_error::system_error(int ev, const error_category& ecat)
186 : runtime_error(__init(error_code(ev, ecat), "")),
187 __ec_(error_code(ev, ecat))
191 system_error::~system_error() _NOEXCEPT
196 __throw_system_error(int ev, const char* what_arg)
198 #ifndef _LIBCPP_NO_EXCEPTIONS
199 throw system_error(error_code(ev, system_category()), what_arg);
206 _LIBCPP_END_NAMESPACE_STD