PMDK C++ bindings  1.10
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-2020, 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 
63 class transaction_error : public std::runtime_error {
64 public:
65  using std::runtime_error::runtime_error;
66 
68  with_pmemobj_errormsg()
69  {
70  (*this) = transaction_error(what() + std::string(": ") +
72  return *this;
73  }
74 };
75 
82 class lock_error : public std::system_error {
83 public:
84  using std::system_error::system_error;
85 
86  lock_error &
87  with_pmemobj_errormsg()
88  {
89  (*this) = lock_error(code(),
90  what() + std::string(": ") +
92  return *this;
93  }
94 };
95 
102 public:
103  using transaction_error::transaction_error;
104 
106  with_pmemobj_errormsg()
107  {
108  (*this) = transaction_alloc_error(what() + std::string(": ") +
109  detail::errormsg());
110  return *this;
111  }
112 };
113 
120  public std::bad_alloc {
121 public:
122  using transaction_alloc_error::transaction_alloc_error;
123  using transaction_alloc_error::what;
124 
126  with_pmemobj_errormsg()
127  {
128  (*this) = transaction_out_of_memory(
129  transaction_alloc_error::what() + std::string(": ") +
130  detail::errormsg());
131  return *this;
132  }
133 };
134 
141 public:
142  using transaction_alloc_error::transaction_alloc_error;
143 
145  with_pmemobj_errormsg()
146  {
147  (*this) = transaction_free_error(what() + std::string(": ") +
148  detail::errormsg());
149  return *this;
150  }
151 };
152 
158 class transaction_scope_error : public std::logic_error {
159 public:
160  using std::logic_error::logic_error;
161 };
162 
168 class manual_tx_abort : public std::runtime_error {
169 public:
170  using std::runtime_error::runtime_error;
171 };
172 
178 class layout_error : public std::runtime_error {
179 public:
180  using std::runtime_error::runtime_error;
181 };
182 
188 class ctl_error : public std::runtime_error {
189 public:
190  using std::runtime_error::runtime_error;
191 
192  ctl_error &
193  with_pmemobj_errormsg()
194  {
195  (*this) = ctl_error(what() + std::string(": ") +
196  detail::errormsg());
197  return *this;
198  }
199 };
200 
207 class defrag_error : public std::runtime_error {
208 public:
209  using std::runtime_error::runtime_error;
210 
211  defrag_error(pobj_defrag_result result, const std::string &msg)
212  : std::runtime_error(msg), result(result)
213  {
214  }
215 
216  defrag_error &
217  with_pmemobj_errormsg()
218  {
219  (*this) = defrag_error(result,
220  what() + std::string(": ") +
221  detail::errormsg());
222  return *this;
223  }
224 
231  pobj_defrag_result result;
232 };
233 
234 } /* namespace pmem */
235 
236 #endif /* LIBPMEMOBJ_CPP_PEXCEPTIONS_HPP */
pmem::transaction_free_error
Custom transaction error class.
Definition: pexceptions.hpp:140
pmem::pool_error
Custom pool error class.
Definition: pexceptions.hpp:45
pmem::transaction_error
Custom transaction error class.
Definition: pexceptions.hpp:63
pmem
Persistent memory namespace.
Definition: allocation_flag.hpp:15
pmem::transaction_out_of_memory
Custom out of memory error class.
Definition: pexceptions.hpp:120
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:231
pmem::lock_error
Custom lock error class.
Definition: pexceptions.hpp:82
pmem::defrag_error
Custom defrag error class.
Definition: pexceptions.hpp:207
pmem::layout_error
Custom layout error class.
Definition: pexceptions.hpp:178
pmem::transaction_scope_error
Custom transaction error class.
Definition: pexceptions.hpp:158
pmem::ctl_error
Custom ctl error class.
Definition: pexceptions.hpp:188
pmem::manual_tx_abort
Custom transaction error class.
Definition: pexceptions.hpp:168
pmem::transaction_alloc_error
Custom transaction error class.
Definition: pexceptions.hpp:101