Jeff Thompson | 86b6d64 | 2013-10-17 15:01:56 -0700 | [diff] [blame] | 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 NDNBOOST_SYSTEM_ERROR_HPP |
| 9 | #define NDNBOOST_SYSTEM_ERROR_HPP |
| 10 | |
| 11 | #include <string> |
| 12 | #include <stdexcept> |
| 13 | #include <cassert> |
| 14 | #include <ndnboost/system/error_code.hpp> |
| 15 | |
| 16 | namespace ndnboost |
| 17 | { |
| 18 | namespace system |
| 19 | { |
| 20 | // class system_error ------------------------------------------------------------// |
| 21 | |
| 22 | class NDNBOOST_SYMBOL_VISIBLE system_error : public std::runtime_error |
| 23 | // NDNBOOST_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 |
| 25 | { |
| 26 | public: |
| 27 | system_error( error_code ec ) |
| 28 | : std::runtime_error(""), m_error_code(ec) {} |
| 29 | |
| 30 | system_error( error_code ec, const std::string & what_arg ) |
| 31 | : std::runtime_error(what_arg), m_error_code(ec) {} |
| 32 | |
| 33 | system_error( error_code ec, const char* what_arg ) |
| 34 | : std::runtime_error(what_arg), m_error_code(ec) {} |
| 35 | |
| 36 | system_error( int ev, const error_category & ecat ) |
| 37 | : std::runtime_error(""), m_error_code(ev,ecat) {} |
| 38 | |
| 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) {} |
| 42 | |
| 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) {} |
| 46 | |
| 47 | virtual ~system_error() throw() {} |
| 48 | |
| 49 | const error_code & code() const throw() { return m_error_code; } |
| 50 | const char * what() const throw(); |
| 51 | |
| 52 | private: |
| 53 | error_code m_error_code; |
| 54 | mutable std::string m_what; |
| 55 | }; |
| 56 | |
| 57 | // implementation ------------------------------------------------------// |
| 58 | |
| 59 | inline const char * system_error::what() const throw() |
| 60 | // see http://www.boost.org/more/error_handling.html for lazy build rationale |
| 61 | { |
| 62 | if ( m_what.empty() ) |
| 63 | { |
| 64 | #ifndef NDNBOOST_NO_EXCEPTIONS |
| 65 | try |
| 66 | #endif |
| 67 | { |
| 68 | m_what = this->std::runtime_error::what(); |
| 69 | if ( !m_what.empty() ) m_what += ": "; |
| 70 | m_what += m_error_code.message(); |
| 71 | } |
| 72 | #ifndef NDNBOOST_NO_EXCEPTIONS |
| 73 | catch (...) { return std::runtime_error::what(); } |
| 74 | #endif |
| 75 | } |
| 76 | return m_what.c_str(); |
| 77 | } |
| 78 | |
| 79 | } // namespace system |
| 80 | } // namespace ndnboost |
| 81 | |
| 82 | #endif // NDNBOOST_SYSTEM_ERROR_HPP |
| 83 | |
| 84 | |