exceptions.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-2015. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/interprocess for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_INTERPROCESS_EXCEPTIONS_HPP
  11. #define BOOST_INTERPROCESS_EXCEPTIONS_HPP
  12. #ifndef BOOST_CONFIG_HPP
  13. # include <boost/config.hpp>
  14. #endif
  15. #
  16. #if defined(BOOST_HAS_PRAGMA_ONCE)
  17. # pragma once
  18. #endif
  19. #include <boost/interprocess/detail/config_begin.hpp>
  20. #include <boost/interprocess/detail/workaround.hpp>
  21. #include <boost/interprocess/errors.hpp>
  22. #include <stdexcept>
  23. //!\file
  24. //!Describes exceptions thrown by interprocess classes
  25. namespace boost {
  26. namespace interprocess {
  27. //!This class is the base class of all exceptions
  28. //!thrown by boost::interprocess
  29. class BOOST_SYMBOL_VISIBLE interprocess_exception : public std::exception
  30. {
  31. public:
  32. interprocess_exception(const char *err) BOOST_NOEXCEPT
  33. : m_err(other_error)
  34. {
  35. try { m_str = err; }
  36. catch (...) {}
  37. }
  38. interprocess_exception(const error_info &err_info, const char *str = 0)
  39. : m_err(err_info)
  40. {
  41. try{
  42. if(m_err.get_native_error() != 0){
  43. fill_system_message(m_err.get_native_error(), m_str);
  44. }
  45. else if(str){
  46. m_str = str;
  47. }
  48. else{
  49. m_str = "boost::interprocess_exception::library_error";
  50. }
  51. }
  52. catch(...){}
  53. }
  54. ~interprocess_exception() BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE {}
  55. const char * what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
  56. { return m_str.c_str(); }
  57. native_error_t get_native_error() const BOOST_NOEXCEPT { return m_err.get_native_error(); }
  58. // Note: a value of other_error implies a library (rather than system) error
  59. error_code_t get_error_code() const BOOST_NOEXCEPT { return m_err.get_error_code(); }
  60. #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
  61. private:
  62. error_info m_err;
  63. std::string m_str;
  64. #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
  65. };
  66. //!This is the exception thrown by shared interprocess_mutex family when a deadlock situation
  67. //!is detected or when using a interprocess_condition the interprocess_mutex is not locked
  68. class BOOST_SYMBOL_VISIBLE lock_exception : public interprocess_exception
  69. {
  70. public:
  71. lock_exception() BOOST_NOEXCEPT
  72. : interprocess_exception(lock_error)
  73. {}
  74. const char* what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
  75. { return "boost::interprocess::lock_exception"; }
  76. };
  77. //!This exception is thrown when a memory request can't be
  78. //!fulfilled.
  79. class BOOST_SYMBOL_VISIBLE bad_alloc : public interprocess_exception
  80. {
  81. public:
  82. bad_alloc() : interprocess_exception("::boost::interprocess::bad_alloc") {}
  83. const char* what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
  84. { return "boost::interprocess::bad_alloc"; }
  85. };
  86. } // namespace interprocess {
  87. } // namespace boost
  88. #include <boost/interprocess/detail/config_end.hpp>
  89. #endif // BOOST_INTERPROCESS_EXCEPTIONS_HPP