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 BOOST_SYMBOL_VISIBLE system_error : public std::runtime_error
23 // BOOST_SYMBOL_VISIBLE is needed by GCC to ensure system_error thrown from a shared
24 // library can be caught. See svn.boost.org/trac/boost/ticket/3697
27 system_error( error_code ec )
28 : std::runtime_error(""), m_error_code(ec) {}
30 system_error( error_code ec, const std::string & what_arg )
31 : std::runtime_error(what_arg), m_error_code(ec) {}
33 system_error( error_code ec, const char* what_arg )
34 : std::runtime_error(what_arg), m_error_code(ec) {}
36 system_error( int ev, const error_category & ecat )
37 : std::runtime_error(""), m_error_code(ev,ecat) {}
39 system_error( int ev, const error_category & ecat,
40 const std::string & what_arg )
41 : std::runtime_error(what_arg), m_error_code(ev,ecat) {}
43 system_error( int ev, const error_category & ecat,
44 const char * what_arg )
45 : std::runtime_error(what_arg), m_error_code(ev,ecat) {}
47 virtual ~system_error() throw() {}
49 const error_code & code() const throw() { return m_error_code; }
50 const char * what() const throw();
53 error_code m_error_code;
54 mutable std::string m_what;
57 // implementation ------------------------------------------------------//
59 inline const char * system_error::what() const throw()
60 // see http://www.boost.org/more/error_handling.html for lazy build rationale
64 #ifndef BOOST_NO_EXCEPTIONS
68 m_what = this->std::runtime_error::what();
69 if ( !m_what.empty() ) m_what += ": ";
70 m_what += m_error_code.message();
72 #ifndef BOOST_NO_EXCEPTIONS
73 catch (...) { return std::runtime_error::what(); }
76 return m_what.c_str();
82 #endif // BOOST_SYSTEM_ERROR_HPP