Chris@16: ////////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost Chris@16: // Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // See http://www.boost.org/libs/interprocess for documentation. Chris@16: // Chris@16: ////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: #ifndef BOOST_INTERPROCESS_EXCEPTIONS_HPP Chris@16: #define BOOST_INTERPROCESS_EXCEPTIONS_HPP Chris@16: Chris@101: #ifndef BOOST_CONFIG_HPP Chris@101: # include Chris@101: #endif Chris@101: # Chris@101: #if defined(BOOST_HAS_PRAGMA_ONCE) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: //!\file Chris@16: //!Describes exceptions thrown by interprocess classes Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: namespace interprocess { Chris@16: Chris@16: //!This class is the base class of all exceptions Chris@16: //!thrown by boost::interprocess Chris@16: class interprocess_exception : public std::exception Chris@16: { Chris@16: public: Chris@16: interprocess_exception(const char *err/*error_code_t ec = other_error*/) Chris@16: : m_err(other_error) Chris@16: { Chris@16: // try { m_str = "boost::interprocess_exception::library_error"; } Chris@16: try { m_str = err; } Chris@16: catch (...) {} Chris@16: } Chris@16: /* Chris@16: interprocess_exception(native_error_t sys_err_code) Chris@16: : m_err(sys_err_code) Chris@16: { Chris@16: try { fill_system_message(m_err.get_native_error(), m_str); } Chris@16: catch (...) {} Chris@16: }*/ Chris@16: Chris@16: interprocess_exception(const error_info &err_info, const char *str = 0) Chris@16: : m_err(err_info) Chris@16: { Chris@16: try{ Chris@16: if(m_err.get_native_error() != 0){ Chris@16: fill_system_message(m_err.get_native_error(), m_str); Chris@16: } Chris@16: else if(str){ Chris@16: m_str = str; Chris@16: } Chris@16: else{ Chris@16: m_str = "boost::interprocess_exception::library_error"; Chris@16: } Chris@16: } Chris@16: catch(...){} Chris@16: } Chris@16: Chris@16: virtual ~interprocess_exception() throw(){} Chris@16: Chris@16: virtual const char * what() const throw() Chris@16: { return m_str.c_str(); } Chris@16: Chris@16: native_error_t get_native_error()const { return m_err.get_native_error(); } Chris@16: Chris@16: // Note: a value of other_error implies a library (rather than system) error Chris@16: error_code_t get_error_code() const { return m_err.get_error_code(); } Chris@16: Chris@101: #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) Chris@16: private: Chris@16: error_info m_err; Chris@16: std::string m_str; Chris@101: #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED Chris@16: }; Chris@16: Chris@16: //!This is the exception thrown by shared interprocess_mutex family when a deadlock situation Chris@16: //!is detected or when using a interprocess_condition the interprocess_mutex is not locked Chris@16: class lock_exception : public interprocess_exception Chris@16: { Chris@16: public: Chris@16: lock_exception() Chris@16: : interprocess_exception(lock_error) Chris@16: {} Chris@16: Chris@16: virtual const char* what() const throw() Chris@16: { return "boost::interprocess::lock_exception"; } Chris@16: }; Chris@16: Chris@16: //!This is the exception thrown by named interprocess_semaphore when a deadlock situation Chris@16: //!is detected or when an error is detected in the post/wait operation Chris@16: /* Chris@16: class sem_exception : public interprocess_exception Chris@16: { Chris@16: public: Chris@16: sem_exception() Chris@16: : interprocess_exception(lock_error) Chris@16: {} Chris@16: Chris@16: virtual const char* what() const throw() Chris@16: { return "boost::interprocess::sem_exception"; } Chris@16: }; Chris@16: */ Chris@16: //!This is the exception thrown by synchronization objects when there is Chris@16: //!an error in a wait() function Chris@16: /* Chris@16: class wait_exception : public interprocess_exception Chris@16: { Chris@16: public: Chris@16: virtual const char* what() const throw() Chris@16: { return "boost::interprocess::wait_exception"; } Chris@16: }; Chris@16: */ Chris@16: Chris@16: //!This exception is thrown when a named object is created Chris@16: //!in "open_only" mode and the resource was not already created Chris@16: /* Chris@16: class not_previously_created : public interprocess_exception Chris@16: { Chris@16: public: Chris@16: virtual const char* what() const throw() Chris@16: { return "boost::interprocess::not_previously_created"; } Chris@16: }; Chris@16: */ Chris@16: Chris@16: //!This exception is thrown when a memory request can't be Chris@16: //!fulfilled. Chris@16: class bad_alloc : public interprocess_exception Chris@16: { Chris@16: public: Chris@16: bad_alloc() : interprocess_exception("::boost::interprocess::bad_alloc"){} Chris@16: virtual const char* what() const throw() Chris@16: { return "boost::interprocess::bad_alloc"; } Chris@16: }; Chris@16: Chris@16: } // namespace interprocess { Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_INTERPROCESS_EXCEPTIONS_HPP