fix doc example typo
[boost.git] / boost / interprocess / exceptions.hpp
blob8bbb21150e34746c14b30aea5d2f93ab8eb6f950
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2005-2008. 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 //////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_INTERPROCESS_EXCEPTIONS_HPP
12 #define BOOST_INTERPROCESS_EXCEPTIONS_HPP
14 #if (defined _MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif
18 #include <boost/interprocess/detail/config_begin.hpp>
19 #include <boost/interprocess/detail/workaround.hpp>
20 #include <boost/interprocess/errors.hpp>
21 #include <stdexcept>
22 #include <new>
24 //!\file
25 //!Describes exceptions thrown by interprocess classes
27 namespace boost {
29 namespace interprocess {
31 //!This class is the base class of all exceptions
32 //!thrown by boost::interprocess
33 class interprocess_exception : public std::exception
35 public:
36 interprocess_exception(error_code_t ec = other_error )
37 : m_err(ec)
39 try { m_str = "boost::interprocess_exception::library_error"; }
40 catch (...) {}
43 interprocess_exception(native_error_t sys_err_code)
44 : m_err(sys_err_code)
46 try { fill_system_message(m_err.get_native_error(), m_str); }
47 catch (...) {}
50 interprocess_exception(const error_info &err_info)
51 : m_err(err_info)
53 try{
54 if(m_err.get_native_error() != 0){
55 fill_system_message(m_err.get_native_error(), m_str);
56 }/*
57 else{
58 m_str = "boost::interprocess_exception::library_error";
59 }*/
61 catch(...){}
64 virtual ~interprocess_exception() throw(){}
66 virtual const char * what() const throw()
67 { return m_str.c_str(); }
69 native_error_t get_native_error()const { return m_err.get_native_error(); }
71 // Note: a value of other_error implies a library (rather than system) error
72 error_code_t get_error_code() const { return m_err.get_error_code(); }
74 /// @cond
75 private:
76 error_info m_err;
77 std::string m_str;
78 /// @endcond
81 //!This is the exception thrown by shared interprocess_mutex family when a deadlock situation
82 //!is detected or when using a interprocess_condition the interprocess_mutex is not locked
83 class lock_exception : public interprocess_exception
85 public:
86 lock_exception()
87 : interprocess_exception(lock_error)
90 virtual const char* what() const throw()
91 { return "boost::interprocess::lock_exception"; }
94 //!This is the exception thrown by named interprocess_semaphore when a deadlock situation
95 //!is detected or when an error is detected in the post/wait operation
97 class sem_exception : public interprocess_exception
99 public:
100 sem_exception()
101 : interprocess_exception(lock_error)
104 virtual const char* what() const throw()
105 { return "boost::interprocess::sem_exception"; }
108 //!This is the exception thrown by synchronization objects when there is
109 //!an error in a wait() function
111 class wait_exception : public interprocess_exception
113 public:
114 virtual const char* what() const throw()
115 { return "boost::interprocess::wait_exception"; }
119 //!This exception is thrown when a named object is created
120 //!in "open_only" mode and the resource was not already created
122 class not_previously_created : public interprocess_exception
124 public:
125 virtual const char* what() const throw()
126 { return "boost::interprocess::not_previously_created"; }
130 //!This exception is thrown when a memory request can't be
131 //!fulfilled.
132 class bad_alloc : public interprocess_exception
134 public:
135 virtual const char* what() const throw()
136 { return "boost::interprocess::bad_alloc"; }
139 } // namespace interprocess {
141 } // namespace boost
143 #include <boost/interprocess/detail/config_end.hpp>
145 #endif // BOOST_INTERPROCESS_EXCEPTIONS_HPP