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