exceptions.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-2012. 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. #if (defined _MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif
  15. #include <boost/interprocess/detail/config_begin.hpp>
  16. #include <boost/interprocess/detail/workaround.hpp>
  17. #include <boost/interprocess/errors.hpp>
  18. #include <stdexcept>
  19. #include <new>
  20. //!\file
  21. //!Describes exceptions thrown by interprocess classes
  22. namespace boost {
  23. namespace interprocess {
  24. //!This class is the base class of all exceptions
  25. //!thrown by boost::interprocess
  26. class interprocess_exception : public std::exception
  27. {
  28. public:
  29. interprocess_exception(const char *err/*error_code_t ec = other_error*/)
  30. : m_err(other_error)
  31. {
  32. // try { m_str = "boost::interprocess_exception::library_error"; }
  33. try { m_str = err; }
  34. catch (...) {}
  35. }
  36. /*
  37. interprocess_exception(native_error_t sys_err_code)
  38. : m_err(sys_err_code)
  39. {
  40. try { fill_system_message(m_err.get_native_error(), m_str); }
  41. catch (...) {}
  42. }*/
  43. interprocess_exception(const error_info &err_info, const char *str = 0)
  44. : m_err(err_info)
  45. {
  46. try{
  47. if(m_err.get_native_error() != 0){
  48. fill_system_message(m_err.get_native_error(), m_str);
  49. }
  50. else if(str){
  51. m_str = str;
  52. }
  53. else{
  54. m_str = "boost::interprocess_exception::library_error";
  55. }
  56. }
  57. catch(...){}
  58. }
  59. virtual ~interprocess_exception() throw(){}
  60. virtual const char * what() const throw()
  61. { return m_str.c_str(); }
  62. native_error_t get_native_error()const { return m_err.get_native_error(); }
  63. // Note: a value of other_error implies a library (rather than system) error
  64. error_code_t get_error_code() const { return m_err.get_error_code(); }
  65. /// @cond
  66. private:
  67. error_info m_err;
  68. std::string m_str;
  69. /// @endcond
  70. };
  71. //!This is the exception thrown by shared interprocess_mutex family when a deadlock situation
  72. //!is detected or when using a interprocess_condition the interprocess_mutex is not locked
  73. class lock_exception : public interprocess_exception
  74. {
  75. public:
  76. lock_exception()
  77. : interprocess_exception(lock_error)
  78. {}
  79. virtual const char* what() const throw()
  80. { return "boost::interprocess::lock_exception"; }
  81. };
  82. //!This is the exception thrown by named interprocess_semaphore when a deadlock situation
  83. //!is detected or when an error is detected in the post/wait operation
  84. /*
  85. class sem_exception : public interprocess_exception
  86. {
  87. public:
  88. sem_exception()
  89. : interprocess_exception(lock_error)
  90. {}
  91. virtual const char* what() const throw()
  92. { return "boost::interprocess::sem_exception"; }
  93. };
  94. */
  95. //!This is the exception thrown by synchronization objects when there is
  96. //!an error in a wait() function
  97. /*
  98. class wait_exception : public interprocess_exception
  99. {
  100. public:
  101. virtual const char* what() const throw()
  102. { return "boost::interprocess::wait_exception"; }
  103. };
  104. */
  105. //!This exception is thrown when a named object is created
  106. //!in "open_only" mode and the resource was not already created
  107. /*
  108. class not_previously_created : public interprocess_exception
  109. {
  110. public:
  111. virtual const char* what() const throw()
  112. { return "boost::interprocess::not_previously_created"; }
  113. };
  114. */
  115. //!This exception is thrown when a memory request can't be
  116. //!fulfilled.
  117. class bad_alloc : public interprocess_exception
  118. {
  119. public:
  120. bad_alloc() : interprocess_exception("::boost::interprocess::bad_alloc"){}
  121. virtual const char* what() const throw()
  122. { return "boost::interprocess::bad_alloc"; }
  123. };
  124. } // namespace interprocess {
  125. } // namespace boost
  126. #include <boost/interprocess/detail/config_end.hpp>
  127. #endif // BOOST_INTERPROCESS_EXCEPTIONS_HPP