PMDK C++ bindings  1.12.1-rc1
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-2022, 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 
47 class pool_error : public std::runtime_error {
48 public:
49  using std::runtime_error::runtime_error;
50 
51  pool_error &
52  with_pmemobj_errormsg()
53  {
54  (*this) = pool_error(what() + std::string(": ") +
56  return *this;
57  }
58 };
59 
65 class transaction_error : public std::runtime_error {
66 public:
67  using std::runtime_error::runtime_error;
68 
70  with_pmemobj_errormsg()
71  {
72  (*this) = transaction_error(what() + std::string(": ") +
74  return *this;
75  }
76 };
77 
84 class lock_error : public std::system_error {
85 public:
86  using std::system_error::system_error;
87 
88  lock_error &
89  with_pmemobj_errormsg()
90  {
91  (*this) = lock_error(code(),
92  what() + std::string(": ") +
94  return *this;
95  }
96 };
97 
104 public:
105  using transaction_error::transaction_error;
106 
108  with_pmemobj_errormsg()
109  {
110  (*this) = transaction_alloc_error(what() + std::string(": ") +
111  detail::errormsg());
112  return *this;
113  }
114 };
115 
125  public std::bad_alloc {
126 public:
127  using transaction_alloc_error::transaction_alloc_error;
128  using transaction_alloc_error::what;
129 
131  with_pmemobj_errormsg()
132  {
133  (*this) = transaction_out_of_memory(
134  transaction_alloc_error::what() + std::string(": ") +
135  detail::errormsg());
136  return *this;
137  }
138 };
139 
146 public:
147  using transaction_alloc_error::transaction_alloc_error;
148 
150  with_pmemobj_errormsg()
151  {
152  (*this) = transaction_free_error(what() + std::string(": ") +
153  detail::errormsg());
154  return *this;
155  }
156 };
157 
163 class transaction_scope_error : public std::logic_error {
164 public:
165  using std::logic_error::logic_error;
166 };
167 
173 class manual_tx_abort : public std::runtime_error {
174 public:
175  using std::runtime_error::runtime_error;
176 };
177 
183 class layout_error : public std::runtime_error {
184 public:
185  using std::runtime_error::runtime_error;
186 };
187 
193 class ctl_error : public std::runtime_error {
194 public:
195  using std::runtime_error::runtime_error;
196 
197  ctl_error &
198  with_pmemobj_errormsg()
199  {
200  (*this) = ctl_error(what() + std::string(": ") +
201  detail::errormsg());
202  return *this;
203  }
204 };
205 
212 class defrag_error : public std::runtime_error {
213 public:
214  using std::runtime_error::runtime_error;
215 
216  defrag_error(pobj_defrag_result result, const std::string &msg)
217  : std::runtime_error(msg), result(result)
218  {
219  }
220 
221  defrag_error &
222  with_pmemobj_errormsg()
223  {
224  (*this) = defrag_error(result,
225  what() + std::string(": ") +
226  detail::errormsg());
227  return *this;
228  }
229 
236  pobj_defrag_result result;
237 };
238 
239 } /* namespace pmem */
240 
241 #endif /* LIBPMEMOBJ_CPP_PEXCEPTIONS_HPP */
pmem::transaction_free_error
Custom transaction error class.
Definition: pexceptions.hpp:145
pmem::pool_error
Custom pool error class.
Definition: pexceptions.hpp:47
pmem::transaction_error
Custom transaction error class.
Definition: pexceptions.hpp:65
pmem
Persistent memory namespace.
Definition: allocation_flag.hpp:15
pmem::transaction_out_of_memory
Custom out of memory error class.
Definition: pexceptions.hpp:125
pmem::detail::errormsg
std::string errormsg(void)
Return last libpmemobj error message as a std::string.
Definition: pexceptions.hpp:29
pmem::defrag_error::result
pobj_defrag_result result
Results of the defragmentation run.
Definition: pexceptions.hpp:236
pmem::lock_error
Custom lock error class.
Definition: pexceptions.hpp:84
pmem::defrag_error
Custom defrag error class.
Definition: pexceptions.hpp:212
pmem::layout_error
Custom layout error class.
Definition: pexceptions.hpp:183
pmem::transaction_scope_error
Custom transaction error class.
Definition: pexceptions.hpp:163
pmem::ctl_error
Custom ctl error class.
Definition: pexceptions.hpp:193
pmem::manual_tx_abort
Custom transaction error class.
Definition: pexceptions.hpp:173
pmem::transaction_alloc_error
Custom transaction error class.
Definition: pexceptions.hpp:103