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>
44 #include <bits/error_constants.h>
48 _GLIBCXX_BEGIN_NAMESPACE(std)
54 extern const error_category& system_category;
61 operator==(const error_category& __other) const
62 { return this == &__other; }
65 operator!=(const error_category& __other) const
66 { return this != &__other; }
68 virtual posix_error::posix_errno
69 posix(int __v) const = 0;
75 error_category(const error_category&);
78 operator=(const error_category&);
84 : _M_value(0), _M_cat(&system_category) { }
86 error_code(int __v, const error_category& __cat) throw()
87 : _M_value(__v), _M_cat(&__cat) { }
89 error_code(posix_error::posix_errno __v)
90 : _M_value(__v), _M_cat(&system_category) { }
93 assign(int __v, const error_category& __cat) throw()
103 _M_cat = &system_category;
107 value() const throw() { return _M_value; }
109 const error_category&
110 category() const { return *_M_cat; }
112 posix_error::posix_errno
113 posix() const throw() { return this->category().posix(_M_value); }
116 // explicit operator bool() const throw()
117 // { return _M_value != 0; }
118 typedef void (*__bool_type)();
120 static void __not_bool_type() { }
122 operator __bool_type() const throw()
123 { return _M_value != 0 ? &__not_bool_type : false; }
125 bool operator==(const error_code& __other) const
126 { return value() == __other.value() && category() == __other.category(); }
128 bool operator!=(const error_code& __other) const
129 { return !(this == &__other); }
133 const error_category* _M_cat;
136 class system_error : public std::runtime_error
142 system_error(const string& __what, error_code __ec = error_code())
143 : runtime_error(__what), _M_code(__ec) { }
145 system_error(const string& __what, int __v, const error_category& __ecat)
146 : runtime_error(__what), _M_code(error_code(__v, __ecat)) { }
148 virtual ~system_error() throw();
151 code() const throw() { return _M_code; }
154 _GLIBCXX_END_NAMESPACE