PMDK C++ bindings  1.13.0-git107.g7e59f08f
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 #include <tuple>
16 
17 #include <libpmemobj/atomic_base.h>
18 #include <libpmemobj/base.h>
19 
21 
22 namespace pmem
23 {
24 
25 namespace detail
26 {
27 
31 inline std::string
32 errormsg(void)
33 {
34 #ifdef _WIN32
35  return std::string(pmemobj_errormsgU());
36 #else
37  return std::string(pmemobj_errormsg());
38 #endif
39 }
40 
49 template <typename ExcT, size_t... I, typename Tuple>
50 ExcT
51 exception_with_errormsg_helper(index_sequence<I...>, Tuple &&args)
52 {
53  static_assert(std::is_rvalue_reference<decltype(args)>::value,
54  "args should be rvalue reference!");
55 
56  auto msg = std::get<sizeof...(I)>(std::move(args)) + std::string(": ") +
58  return ExcT(std::get<I>(std::move(args))..., std::move(msg));
59 }
60 
67 template <class ExcT, typename... Args>
68 ExcT
69 exception_with_errormsg(Args &&... args)
70 {
71  return exception_with_errormsg_helper<ExcT>(
72  make_index_sequence<sizeof...(Args) - 1>{},
73  std::forward_as_tuple(std::forward<Args>(args)...));
74 }
75 } /* namespace detail */
76 
84 class pool_error : public std::runtime_error {
85 public:
86  using std::runtime_error::runtime_error;
87 };
88 
98 public:
99  using pool_error::pool_error;
100 };
101 
109 class transaction_error : public std::runtime_error {
110 public:
111  using std::runtime_error::runtime_error;
112 };
113 
121 class lock_error : public std::system_error {
122 public:
123  using std::system_error::system_error;
124 };
125 
133 public:
134  using transaction_error::transaction_error;
135 };
136 
144  public std::bad_alloc {
145 public:
146  using transaction_alloc_error::transaction_alloc_error;
147  using transaction_alloc_error::what;
148 };
149 
157 public:
158  using transaction_alloc_error::transaction_alloc_error;
159 };
160 
167 class transaction_scope_error : public std::logic_error {
168 public:
169  using std::logic_error::logic_error;
170 };
171 
178 class manual_tx_abort : public std::runtime_error {
179 public:
180  using std::runtime_error::runtime_error;
181 };
182 
189 class layout_error : public std::runtime_error {
190 public:
191  using std::runtime_error::runtime_error;
192 };
193 
200 class ctl_error : public std::runtime_error {
201 public:
202  using std::runtime_error::runtime_error;
203 };
204 
212 class defrag_error : public std::runtime_error {
213 public:
214  using std::runtime_error::runtime_error;
215 
222  defrag_error(pobj_defrag_result result, const std::string &msg)
223  : std::runtime_error(msg), result(result)
224  {
225  }
226 
233  pobj_defrag_result result;
234 };
235 
236 } /* namespace pmem */
237 
238 #endif /* LIBPMEMOBJ_CPP_PEXCEPTIONS_HPP */
Custom ctl error class.
Definition: pexceptions.hpp:200
Custom defrag error class.
Definition: pexceptions.hpp:212
pobj_defrag_result result
Results of the defragmentation run.
Definition: pexceptions.hpp:233
defrag_error(pobj_defrag_result result, const std::string &msg)
Construct error with partial results.
Definition: pexceptions.hpp:222
Custom layout error class.
Definition: pexceptions.hpp:189
Custom lock error class.
Definition: pexceptions.hpp:121
Custom transaction error class.
Definition: pexceptions.hpp:178
Custom pool error class.
Definition: pexceptions.hpp:84
Custom pool error class.
Definition: pexceptions.hpp:97
Custom transaction error class.
Definition: pexceptions.hpp:132
Custom transaction error class.
Definition: pexceptions.hpp:109
Custom transaction error class.
Definition: pexceptions.hpp:156
Custom out of memory error class.
Definition: pexceptions.hpp:144
Custom transaction error class.
Definition: pexceptions.hpp:167
basic_string< char > string
The most typical string usage - the char specialization.
Definition: string.hpp:24
Create c++14 style index sequence.
ExcT exception_with_errormsg_helper(index_sequence< I... >, Tuple &&args)
Helper for exception_with_errormsg.
Definition: pexceptions.hpp:51
ExcT exception_with_errormsg(Args &&... args)
Generic error message decorator for pmemobj-based exceptions.
Definition: pexceptions.hpp:69
std::string errormsg(void)
Return last libpmemobj error message as a std::string.
Definition: pexceptions.hpp:32
Persistent memory namespace.
Definition: allocation_flag.hpp:15