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 #include "system_error"
14 _LIBCPP_BEGIN_NAMESPACE_STD
16 // class error_category
18 error_category::error_category() _NOEXCEPT
22 error_category::~error_category() _NOEXCEPT
27 error_category::default_error_condition(int ev) const _NOEXCEPT
29 return error_condition(ev, *this);
33 error_category::equivalent(int code, const error_condition& condition) const _NOEXCEPT
35 return default_error_condition(code) == condition;
39 error_category::equivalent(const error_code& code, int condition) const _NOEXCEPT
41 return *this == code.category() && code.value() == condition;
45 __do_message::message(int ev) const
47 return string(strerror(ev));
50 class _LIBCPP_HIDDEN __generic_error_category
54 virtual const char* name() const _NOEXCEPT;
55 virtual string message(int ev) const;
59 __generic_error_category::name() const _NOEXCEPT
65 __generic_error_category::message(int ev) const
69 return string("unspecified generic_category error");
71 return __do_message::message(ev);
75 generic_category() _NOEXCEPT
77 static __generic_error_category s;
81 class _LIBCPP_HIDDEN __system_error_category
85 virtual const char* name() const _NOEXCEPT;
86 virtual string message(int ev) const;
87 virtual error_condition default_error_condition(int ev) const _NOEXCEPT;
91 __system_error_category::name() const _NOEXCEPT
97 __system_error_category::message(int ev) const
101 return string("unspecified system_category error");
103 return __do_message::message(ev);
107 __system_error_category::default_error_condition(int ev) const _NOEXCEPT
111 return error_condition(ev, system_category());
113 return error_condition(ev, generic_category());
116 const error_category&
117 system_category() _NOEXCEPT
119 static __system_error_category s;
126 error_condition::message() const
128 return __cat_->message(__val_);
134 error_code::message() const
136 return __cat_->message(__val_);
142 system_error::__init(const error_code& ec, string what_arg)
146 if (!what_arg.empty())
148 what_arg += ec.message();
150 return _VSTD::move(what_arg);
153 system_error::system_error(error_code ec, const string& what_arg)
154 : runtime_error(__init(ec, what_arg)),
159 system_error::system_error(error_code ec, const char* what_arg)
160 : runtime_error(__init(ec, what_arg)),
165 system_error::system_error(error_code ec)
166 : runtime_error(__init(ec, "")),
171 system_error::system_error(int ev, const error_category& ecat, const string& what_arg)
172 : runtime_error(__init(error_code(ev, ecat), what_arg)),
173 __ec_(error_code(ev, ecat))
177 system_error::system_error(int ev, const error_category& ecat, const char* what_arg)
178 : runtime_error(__init(error_code(ev, ecat), what_arg)),
179 __ec_(error_code(ev, ecat))
183 system_error::system_error(int ev, const error_category& ecat)
184 : runtime_error(__init(error_code(ev, ecat), "")),
185 __ec_(error_code(ev, ecat))
189 system_error::~system_error() _NOEXCEPT
194 __throw_system_error(int ev, const char* what_arg)
196 #ifndef _LIBCPP_NO_EXCEPTIONS
197 throw system_error(error_code(ev, system_category()), what_arg);
201 _LIBCPP_END_NAMESPACE_STD