PMDK C++ bindings  1.9.1
This is the C++ bindings documentation for PMDK's libpmemobj.
pexceptions.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2016-2022, Intel Corporation
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  *
16  * * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
38 #ifndef LIBPMEMOBJ_CPP_PEXCEPTIONS_HPP
39 #define LIBPMEMOBJ_CPP_PEXCEPTIONS_HPP
40 
41 #include <stdexcept>
42 #include <string>
43 #include <system_error>
44 
45 #include <libpmemobj/atomic_base.h>
46 #include <libpmemobj/base.h>
47 
48 namespace pmem
49 {
50 
51 namespace detail
52 {
53 
57 inline std::string
58 errormsg(void)
59 {
60 #ifdef _WIN32
61  return std::string(pmemobj_errormsgU());
62 #else
63  return std::string(pmemobj_errormsg());
64 #endif
65 }
66 } /* namespace detail */
67 
76 class pool_error : public std::runtime_error {
77 public:
78  using std::runtime_error::runtime_error;
79 
80  pool_error &
81  with_pmemobj_errormsg()
82  {
83  (*this) = pool_error(what() + std::string(": ") +
85  return *this;
86  }
87 };
88 
94 class transaction_error : public std::runtime_error {
95 public:
96  using std::runtime_error::runtime_error;
97 
99  with_pmemobj_errormsg()
100  {
101  (*this) = transaction_error(what() + std::string(": ") +
102  detail::errormsg());
103  return *this;
104  }
105 };
106 
113 class lock_error : public std::system_error {
114 public:
115  using std::system_error::system_error;
116 
117  lock_error &
118  with_pmemobj_errormsg()
119  {
120  (*this) = lock_error(code(),
121  what() + std::string(": ") +
122  detail::errormsg());
123  return *this;
124  }
125 };
126 
133 public:
134  using transaction_error::transaction_error;
135 
137  with_pmemobj_errormsg()
138  {
139  (*this) = transaction_alloc_error(what() + std::string(": ") +
140  detail::errormsg());
141  return *this;
142  }
143 };
144 
154  public std::bad_alloc {
155 public:
156  using transaction_alloc_error::transaction_alloc_error;
157  using transaction_alloc_error::what;
158 
160  with_pmemobj_errormsg()
161  {
162  (*this) = transaction_out_of_memory(
163  transaction_alloc_error::what() + std::string(": ") +
164  detail::errormsg());
165  return *this;
166  }
167 };
168 
175 public:
176  using transaction_alloc_error::transaction_alloc_error;
177 
179  with_pmemobj_errormsg()
180  {
181  (*this) = transaction_free_error(what() + std::string(": ") +
182  detail::errormsg());
183  return *this;
184  }
185 };
186 
192 class transaction_scope_error : public std::logic_error {
193 public:
194  using std::logic_error::logic_error;
195 };
196 
202 class manual_tx_abort : public std::runtime_error {
203 public:
204  using std::runtime_error::runtime_error;
205 };
206 
212 class layout_error : public std::runtime_error {
213 public:
214  using std::runtime_error::runtime_error;
215 };
216 
222 class ctl_error : public std::runtime_error {
223 public:
224  using std::runtime_error::runtime_error;
225 
226  ctl_error &
227  with_pmemobj_errormsg()
228  {
229  (*this) = ctl_error(what() + std::string(": ") +
230  detail::errormsg());
231  return *this;
232  }
233 };
234 
241 class defrag_error : public std::runtime_error {
242 public:
243  using std::runtime_error::runtime_error;
244 
245  defrag_error(pobj_defrag_result result, const std::string &msg)
246  : std::runtime_error(msg), result(result)
247  {
248  }
249 
250  defrag_error &
251  with_pmemobj_errormsg()
252  {
253  (*this) = defrag_error(result,
254  what() + std::string(": ") +
255  detail::errormsg());
256  return *this;
257  }
258 
265  pobj_defrag_result result;
266 };
267 
268 } /* namespace pmem */
269 
270 #endif /* LIBPMEMOBJ_CPP_PEXCEPTIONS_HPP */
pmem::transaction_free_error
Custom transaction error class.
Definition: pexceptions.hpp:174
pmem::pool_error
Custom pool error class.
Definition: pexceptions.hpp:76
pmem::transaction_error
Custom transaction error class.
Definition: pexceptions.hpp:94
pmem
Persistent memory namespace.
Definition: allocation_flag.hpp:44
pmem::transaction_out_of_memory
Custom out of memory error class.
Definition: pexceptions.hpp:154
pmem::detail::errormsg
std::string errormsg(void)
Return last libpmemobj error message as a std::string.
Definition: pexceptions.hpp:58
pmem::defrag_error::result
pobj_defrag_result result
Results of the defragmentation run.
Definition: pexceptions.hpp:265
pmem::lock_error
Custom lock error class.
Definition: pexceptions.hpp:113
pmem::defrag_error
Custom defrag error class.
Definition: pexceptions.hpp:241
pmem::layout_error
Custom layout error class.
Definition: pexceptions.hpp:212
pmem::transaction_scope_error
Custom transaction error class.
Definition: pexceptions.hpp:192
pmem::ctl_error
Custom ctl error class.
Definition: pexceptions.hpp:222
pmem::manual_tx_abort
Custom transaction error class.
Definition: pexceptions.hpp:202
pmem::transaction_alloc_error
Custom transaction error class.
Definition: pexceptions.hpp:132