1 // <system_error> -*- C++ -*-
3 // Copyright (C) 2007 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 51 Franklin Street, Fifth Floor,
19 // Boston, MA 02110-1301, USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 /** @file include/system_error
31 * This is a Standard C++ Library header.
34 #ifndef _GLIBCXX_SYSTEM_ERROR
35 #define _GLIBCXX_SYSTEM_ERROR 1
37 #pragma GCC system_header
39 #ifndef __GXX_EXPERIMENTAL_CXX0X__
40 # include <c++0x_warning.h>
43 #include <bits/c++config.h>
48 _GLIBCXX_BEGIN_NAMESPACE(std)
54 extern const error_category& system_category;
58 address_family_not_supported = EAFNOSUPPORT,
59 address_in_use = EADDRINUSE,
60 address_not_available = EADDRNOTAVAIL,
61 already_connected = EISCONN,
62 argument_list_too_long = E2BIG,
63 argument_out_of_domain = EDOM,
65 bad_file_descriptor = EBADF,
66 bad_message = EBADMSG,
68 connection_aborted = ECONNABORTED,
69 connection_already_in_progress = EALREADY,
70 connection_refused = ECONNREFUSED,
71 connection_reset = ECONNRESET,
72 cross_device_link = EXDEV,
73 destination_address_required = EDESTADDRREQ,
74 device_or_resource_busy = EBUSY,
75 directory_not_empty = ENOTEMPTY,
76 executable_format_error = ENOEXEC,
78 file_too_large = EFBIG,
79 filename_too_long = ENAMETOOLONG,
80 function_not_supported = ENOSYS,
81 host_unreachable = EHOSTUNREACH,
82 identifier_removed = EIDRM,
83 illegal_byte_sequence = EILSEQ,
84 inappropriate_io_control_operation = ENOTTY,
86 invalid_argument = EINVAL,
87 invalid_seek = ESPIPE,
89 is_a_directory = EISDIR,
90 message_size = EMSGSIZE,
91 network_down = ENETDOWN,
92 network_reset = ENETRESET,
93 network_unreachable = ENETUNREACH,
94 no_buffer_space = ENOBUFS,
95 no_child_process = ECHILD,
96 #ifdef _GLIBCXX_HAVE_ENOLINK
99 no_lock_available = ENOLCK,
100 no_message_available = ENODATA,
102 no_protocol_option = ENOPROTOOPT,
103 no_space_on_device = ENOSPC,
104 no_stream_resources = ENOSR,
105 no_such_device_or_address = ENXIO,
106 no_such_device = ENODEV,
107 no_such_file_or_directory = ENOENT,
108 no_such_process = ESRCH,
109 not_a_directory = ENOTDIR,
110 not_a_socket = ENOTSOCK,
111 not_a_stream = ENOSTR,
112 not_connected = ENOTCONN,
113 not_enough_memory = ENOMEM,
114 not_supported = ENOTSUP,
115 operation_canceled = ECANCELED,
116 operation_in_progress = EINPROGRESS,
117 operation_not_permitted = EPERM,
118 operation_not_supported = EOPNOTSUPP,
119 operation_would_block = EWOULDBLOCK,
120 #ifdef _GLIBCXX_HAVE_EOWNERDEAD
121 owner_dead = EOWNERDEAD,
123 permission_denied = EACCES,
124 #ifdef _GLIBCXX_HAVE_EPROTO
125 protocol_error = EPROTO,
127 protocol_not_supported = EPROTONOSUPPORT,
128 read_only_file_system = EROFS,
129 resource_deadlock_would_occur = EDEADLK,
130 resource_unavailable_try_again = EAGAIN,
131 result_out_of_range = ERANGE,
132 #ifdef _GLIBCXX_HAVE_ENOTRECOVERABLE
133 state_not_recoverable = ENOTRECOVERABLE,
135 stream_timeout = ETIME,
136 text_file_busy = ETXTBSY,
137 timed_out = ETIMEDOUT,
138 too_many_files_open_in_system = ENFILE,
139 too_many_files_open = EMFILE,
140 too_many_links = EMLINK,
141 too_many_synbolic_link_levels = ELOOP,
142 value_too_large = EOVERFLOW,
143 wrong_protocol_type = EPROTOTYPE,
144 no_posix_equivalent = 1L << 16
147 struct error_category
152 operator==(const error_category& __other) const
153 { return this == &__other; }
156 operator!=(const error_category& __other) const
157 { return this != &__other; }
160 posix(int __v) const = 0;
162 virtual const string&
166 error_category(const error_category&);
169 operator=(const error_category&);
175 : _M_value(0), _M_cat(&system_category) { }
177 error_code(int __v, const error_category& __cat) throw()
178 : _M_value(__v), _M_cat(&__cat) { }
180 error_code(posix_errno __v)
181 : _M_value(__v), _M_cat(&system_category) { }
184 assign(int __v, const error_category& __cat) throw()
194 _M_cat = &system_category;
198 value() const throw() { return _M_value; }
200 const error_category&
201 category() const { return *_M_cat; }
204 posix() const throw() { return this->category().posix(_M_value); }
207 // explicit operator bool() const throw()
208 // { return _M_value != 0; }
209 typedef void (*__bool_type)();
211 static void __not_bool_type() { }
213 operator __bool_type() const throw()
214 { return _M_value != 0 ? &__not_bool_type : false; }
216 bool operator==(const error_code& __other) const
217 { return value() == __other.value() && category() == __other.category(); }
219 bool operator!=(const error_code& __other) const
220 { return !(this == &__other); }
224 const error_category* _M_cat;
227 class system_error : public std::runtime_error
233 system_error(const string& __what, error_code __ec = error_code())
234 : runtime_error(__what), _M_code(__ec) { }
236 system_error(const string& __what, int __v, const error_category& __ecat)
237 : runtime_error(__what), _M_code(error_code(__v, __ecat)) { }
239 virtual ~system_error() throw();
242 code() const throw() { return _M_code; }
245 _GLIBCXX_END_NAMESPACE