PMDK C++ bindings  1.13.0-git23.gf49772ac
This is the C++ bindings documentation for PMDK's libpmemobj.
pexceptions.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-3-Clause
2 /* Copyright 2016-2021, Intel Corporation */
3 
9 #ifndef LIBPMEMOBJ_CPP_PEXCEPTIONS_HPP
10 #define LIBPMEMOBJ_CPP_PEXCEPTIONS_HPP
11 
12 #include <stdexcept>
13 #include <string>
14 #include <system_error>
15 
16 #include <libpmemobj/atomic_base.h>
17 #include <libpmemobj/base.h>
18 
19 namespace pmem
20 {
21 
22 namespace detail
23 {
24 
28 inline std::string
29 errormsg(void)
30 {
31 #ifdef _WIN32
32  return std::string(pmemobj_errormsgU());
33 #else
34  return std::string(pmemobj_errormsg());
35 #endif
36 }
37 } /* namespace detail */
38 
45 class pool_error : public std::runtime_error {
46 public:
47  using std::runtime_error::runtime_error;
48 
49  pool_error &
50  with_pmemobj_errormsg()
51  {
52  (*this) = pool_error(what() + std::string(": ") +
54  return *this;
55  }
56 };
57 
64 public:
65  using pool_error::pool_error;
66 
68  with_pmemobj_errormsg()
69  {
70  (*this) = pool_invalid_argument(what() + std::string(": ") +
72  return *this;
73  }
74 };
75 
81 class transaction_error : public std::runtime_error {
82 public:
83  using std::runtime_error::runtime_error;
84 
86  with_pmemobj_errormsg()
87  {
88  (*this) = transaction_error(what() + std::string(": ") +
90  return *this;
91  }
92 };
93 
100 class lock_error : public std::system_error {
101 public:
102  using std::system_error::system_error;
103 
104  lock_error &
105  with_pmemobj_errormsg()
106  {
107  (*this) = lock_error(code(),
108  what() + std::string(": ") +
109  detail::errormsg());
110  return *this;
111  }
112 };
113 
120 public:
121  using transaction_error::transaction_error;
122 
124  with_pmemobj_errormsg()
125  {
126  (*this) = transaction_alloc_error(what() + std::string(": ") +
127  detail::errormsg());
128  return *this;
129  }
130 };
131 
138  public std::bad_alloc {
139 public:
140  using transaction_alloc_error::transaction_alloc_error;
141  using transaction_alloc_error::what;
142 
144  with_pmemobj_errormsg()
145  {
146  (*this) = transaction_out_of_memory(
147  transaction_alloc_error::what() + std::string(": ") +
148  detail::errormsg());
149  return *this;
150  }
151 };
152 
159 public:
160  using transaction_alloc_error::transaction_alloc_error;
161 
163  with_pmemobj_errormsg()
164  {
165  (*this) = transaction_free_error(what() + std::string(": ") +
166  detail::errormsg());
167  return *this;
168  }
169 };
170 
176 class transaction_scope_error : public std::logic_error {
177 public:
178  using std::logic_error::logic_error;
179 };
180 
186 class manual_tx_abort : public std::runtime_error {
187 public:
188  using std::runtime_error::runtime_error;
189 };
190 
196 class layout_error : public std::runtime_error {
197 public:
198  using std::runtime_error::runtime_error;
199 };
200 
206 class ctl_error : public std::runtime_error {
207 public:
208  using std::runtime_error::runtime_error;
209 
210  ctl_error &
211  with_pmemobj_errormsg()
212  {
213  (*this) = ctl_error(what() + std::string(": ") +
214  detail::errormsg());
215  return *this;
216  }
217 };
218 
225 class defrag_error : public std::runtime_error {
226 public:
227  using std::runtime_error::runtime_error;
228 
229  defrag_error(pobj_defrag_result result, const std::string &msg)
230  : std::runtime_error(msg), result(result)
231  {
232  }
233 
234  defrag_error &
235  with_pmemobj_errormsg()
236  {
237  (*this) = defrag_error(result,
238  what() + std::string(": ") +
239  detail::errormsg());
240  return *this;
241  }
242 
249  pobj_defrag_result result;
250 };
251 
252 } /* namespace pmem */
253 
254 #endif /* LIBPMEMOBJ_CPP_PEXCEPTIONS_HPP */
Custom ctl error class.
Definition: pexceptions.hpp:206
Custom defrag error class.
Definition: pexceptions.hpp:225
pobj_defrag_result result
Results of the defragmentation run.
Definition: pexceptions.hpp:249
Custom layout error class.
Definition: pexceptions.hpp:196
Custom lock error class.
Definition: pexceptions.hpp:100
Custom transaction error class.
Definition: pexceptions.hpp:186
Custom pool error class.
Definition: pexceptions.hpp:45
Custom pool error class.
Definition: pexceptions.hpp:63
Custom transaction error class.
Definition: pexceptions.hpp:119
Custom transaction error class.
Definition: pexceptions.hpp:81
Custom transaction error class.
Definition: pexceptions.hpp:158
Custom out of memory error class.
Definition: pexceptions.hpp:138
Custom transaction error class.
Definition: pexceptions.hpp:176
std::string errormsg(void)
Return last libpmemobj error message as a std::string.
Definition: pexceptions.hpp:29
Persistent memory namespace.
Definition: allocation_flag.hpp:15