1 // Boost system_error.hpp --------------------------------------------------//
\r
3 // Copyright Beman Dawes 2006
\r
5 // Distributed under the Boost Software License, Version 1.0. (See accompanying
\r
6 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
\r
8 #ifndef BOOST_SYSTEM_ERROR_HPP
\r
9 #define BOOST_SYSTEM_ERROR_HPP
\r
12 #include <stdexcept>
\r
14 #include <boost/system/error_code.hpp>
\r
20 // class system_error --------------------------------------------------//
\r
22 class system_error : public std::runtime_error
\r
25 system_error( error_code ec )
\r
26 : std::runtime_error(""), m_error_code(ec) {}
\r
28 system_error( error_code ec, const std::string & what_arg )
\r
29 : std::runtime_error(what_arg), m_error_code(ec) {}
\r
31 system_error( error_code ec, const char* what_arg )
\r
32 : std::runtime_error(what_arg), m_error_code(ec) {}
\r
34 system_error( int ev, const error_category & ecat )
\r
35 : std::runtime_error(""), m_error_code(ev,ecat) {}
\r
37 system_error( int ev, const error_category & ecat,
\r
38 const std::string & what_arg )
\r
39 : std::runtime_error(what_arg), m_error_code(ev,ecat) {}
\r
41 system_error( int ev, const error_category & ecat,
\r
42 const char * what_arg )
\r
43 : std::runtime_error(what_arg), m_error_code(ev,ecat) {}
\r
45 virtual ~system_error() throw() {}
\r
47 const error_code & code() const throw() { return m_error_code; }
\r
48 const char * what() const throw();
\r
51 error_code m_error_code;
\r
52 mutable std::string m_what;
\r
55 // implementation ------------------------------------------------------//
\r
57 inline const char * system_error::what() const throw()
\r
58 // see http://www.boost.org/more/error_handling.html for lazy build rationale
\r
60 if ( m_what.empty() )
\r
64 m_what = this->std::runtime_error::what();
\r
67 if ( !m_what.empty() ) m_what += ": ";
\r
68 m_what += m_error_code.message();
\r
71 catch (...) { return std::runtime_error::what(); }
\r
73 return m_what.c_str();
\r
76 } // namespace system
\r
77 } // namespace boost
\r
79 #endif // BOOST_SYSTEM_ERROR_HPP
\r