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,
97 #ifdef _GLIBCXX_HAVE_ENOLINK
100 no_lock_available = ENOLCK,
102 #ifdef _GLIBCXX_HAVE_ENODATA
103 no_message_available = ENODATA,
107 no_protocol_option = ENOPROTOOPT,
108 no_space_on_device = ENOSPC,
110 #ifdef _GLIBCXX_HAVE_ENOSR
111 no_stream_resources = ENOSR,
114 no_such_device_or_address = ENXIO,
115 no_such_device = ENODEV,
116 no_such_file_or_directory = ENOENT,
117 no_such_process = ESRCH,
118 not_a_directory = ENOTDIR,
119 not_a_socket = ENOTSOCK,
121 #ifdef _GLIBCXX_HAVE_ENOSTR
122 not_a_stream = ENOSTR,
125 not_connected = ENOTCONN,
126 not_enough_memory = ENOMEM,
127 not_supported = ENOTSUP,
128 operation_canceled = ECANCELED,
129 operation_in_progress = EINPROGRESS,
130 operation_not_permitted = EPERM,
131 operation_not_supported = EOPNOTSUPP,
132 operation_would_block = EWOULDBLOCK,
133 #ifdef _GLIBCXX_HAVE_EOWNERDEAD
134 owner_dead = EOWNERDEAD,
136 permission_denied = EACCES,
137 #ifdef _GLIBCXX_HAVE_EPROTO
138 protocol_error = EPROTO,
140 protocol_not_supported = EPROTONOSUPPORT,
141 read_only_file_system = EROFS,
142 resource_deadlock_would_occur = EDEADLK,
143 resource_unavailable_try_again = EAGAIN,
144 result_out_of_range = ERANGE,
145 #ifdef _GLIBCXX_HAVE_ENOTRECOVERABLE
146 state_not_recoverable = ENOTRECOVERABLE,
149 #ifdef _GLIBCXX_HAVE_ETIME
150 stream_timeout = ETIME,
153 text_file_busy = ETXTBSY,
154 timed_out = ETIMEDOUT,
155 too_many_files_open_in_system = ENFILE,
156 too_many_files_open = EMFILE,
157 too_many_links = EMLINK,
158 too_many_synbolic_link_levels = ELOOP,
159 value_too_large = EOVERFLOW,
160 wrong_protocol_type = EPROTOTYPE,
161 no_posix_equivalent = 1L << 16
164 struct error_category
169 operator==(const error_category& __other) const
170 { return this == &__other; }
173 operator!=(const error_category& __other) const
174 { return this != &__other; }
177 posix(int __v) const = 0;
179 virtual const string&
183 error_category(const error_category&);
186 operator=(const error_category&);
192 : _M_value(0), _M_cat(&system_category) { }
194 error_code(int __v, const error_category& __cat) throw()
195 : _M_value(__v), _M_cat(&__cat) { }
197 error_code(posix_errno __v)
198 : _M_value(__v), _M_cat(&system_category) { }
201 assign(int __v, const error_category& __cat) throw()
211 _M_cat = &system_category;
215 value() const throw() { return _M_value; }
217 const error_category&
218 category() const { return *_M_cat; }
221 posix() const throw() { return this->category().posix(_M_value); }
224 // explicit operator bool() const throw()
225 // { return _M_value != 0; }
226 typedef void (*__bool_type)();
228 static void __not_bool_type() { }
230 operator __bool_type() const throw()
231 { return _M_value != 0 ? &__not_bool_type : false; }
233 bool operator==(const error_code& __other) const
234 { return value() == __other.value() && category() == __other.category(); }
236 bool operator!=(const error_code& __other) const
237 { return !(this == &__other); }
241 const error_category* _M_cat;
244 class system_error : public std::runtime_error
250 system_error(const string& __what, error_code __ec = error_code())
251 : runtime_error(__what), _M_code(__ec) { }
253 system_error(const string& __what, int __v, const error_category& __ecat)
254 : runtime_error(__what), _M_code(error_code(__v, __ecat)) { }
256 virtual ~system_error() throw();
259 code() const throw() { return _M_code; }
262 _GLIBCXX_END_NAMESPACE