fix doc example typo
[boost.git] / boost / system / system_error.hpp
blob409164735232fcb83397343805a8504118b2858c
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
11 #include <string>
12 #include <stdexcept>
13 #include <cassert>
14 #include <boost/system/error_code.hpp>
16 namespace boost
18 namespace system
20 // class system_error --------------------------------------------------//
22 class system_error : public std::runtime_error
24 public:
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();
50 private:
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
60 if ( m_what.empty() )
62 try
64 m_what = this->std::runtime_error::what();
65 if ( m_error_code )
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();
76 } // namespace system
77 } // namespace boost
79 #endif // BOOST_SYSTEM_ERROR_HPP