imgtools/imglib/boostlibrary/boost/system/system_error.hpp
changeset 600 6d08f4a05d93
equal deleted inserted replaced
599:fa7a3cc6effd 600:6d08f4a05d93
       
     1 //  Boost system_error.hpp  --------------------------------------------------//
       
     2 
       
     3 //  Copyright Beman Dawes 2006
       
     4 
       
     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)
       
     7 
       
     8 #ifndef BOOST_SYSTEM_ERROR_HPP
       
     9 #define BOOST_SYSTEM_ERROR_HPP
       
    10 
       
    11 #include <string>
       
    12 #include <stdexcept>
       
    13 #include <cassert>
       
    14 #include <boost/system/error_code.hpp>
       
    15 
       
    16 namespace boost
       
    17 {
       
    18   namespace system
       
    19   {
       
    20     //  class system_error  --------------------------------------------------//
       
    21 
       
    22     class system_error : public std::runtime_error
       
    23     {
       
    24     public:
       
    25       system_error( error_code ec )
       
    26           : std::runtime_error(""), m_error_code(ec) {}
       
    27 
       
    28       system_error( error_code ec, const std::string & what_arg )
       
    29           : std::runtime_error(what_arg), m_error_code(ec) {}
       
    30 
       
    31       system_error( error_code ec, const char* what_arg )
       
    32           : std::runtime_error(what_arg), m_error_code(ec) {}
       
    33 
       
    34       system_error( int ev, const error_category & ecat )
       
    35           : std::runtime_error(""), m_error_code(ev,ecat) {}
       
    36 
       
    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) {}
       
    40 
       
    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) {}
       
    44 
       
    45       virtual ~system_error() throw() {}
       
    46 
       
    47       const error_code &  code() const throw() { return m_error_code; }
       
    48       const char *        what() const throw();
       
    49 
       
    50     private:
       
    51       error_code           m_error_code;
       
    52       mutable std::string  m_what;
       
    53     };
       
    54 
       
    55     //  implementation  ------------------------------------------------------//
       
    56 
       
    57     inline const char * system_error::what() const throw()
       
    58     // see http://www.boost.org/more/error_handling.html for lazy build rationale
       
    59     {
       
    60       if ( m_what.empty() )
       
    61       {
       
    62         try
       
    63         {
       
    64           m_what = this->std::runtime_error::what();
       
    65           if ( m_error_code )
       
    66           {
       
    67             if ( !m_what.empty() ) m_what += ": ";
       
    68             m_what += m_error_code.message();
       
    69           }
       
    70         }
       
    71         catch (...) { return std::runtime_error::what(); }
       
    72       }
       
    73       return m_what.c_str();
       
    74     }
       
    75 
       
    76   } // namespace system
       
    77 } // namespace boost
       
    78 
       
    79 #endif // BOOST_SYSTEM_ERROR_HPP
       
    80 
       
    81