PMDK C++ bindings  1.9
This is the C++ bindings documentation for PMDK's libpmemobj.
pexceptions.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2016-2020, 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 
74 class pool_error : public std::runtime_error {
75 public:
76  using std::runtime_error::runtime_error;
77 
78  pool_error &
79  with_pmemobj_errormsg()
80  {
81  (*this) = pool_error(what() + std::string(": ") +
83  return *this;
84  }
85 };
86 
92 class transaction_error : public std::runtime_error {
93 public:
94  using std::runtime_error::runtime_error;
95 
97  with_pmemobj_errormsg()
98  {
99  (*this) = transaction_error(what() + std::string(": ") +
100  detail::errormsg());
101  return *this;
102  }
103 };
104 
111 class lock_error : public std::system_error {
112 public:
113  using std::system_error::system_error;
114 
115  lock_error &
116  with_pmemobj_errormsg()
117  {
118  (*this) = lock_error(code(),
119  what() + std::string(": ") +
120  detail::errormsg());
121  return *this;
122  }
123 };
124 
131 public:
132  using transaction_error::transaction_error;
133 
135  with_pmemobj_errormsg()
136  {
137  (*this) = transaction_alloc_error(what() + std::string(": ") +
138  detail::errormsg());
139  return *this;
140  }
141 };
142 
149  public std::bad_alloc {
150 public:
151  using transaction_alloc_error::transaction_alloc_error;
152  using transaction_alloc_error::what;
153 
155  with_pmemobj_errormsg()
156  {
157  (*this) = transaction_out_of_memory(
158  transaction_alloc_error::what() + std::string(": ") +
159  detail::errormsg());
160  return *this;
161  }
162 };
163 
170 public:
171  using transaction_alloc_error::transaction_alloc_error;
172 
174  with_pmemobj_errormsg()
175  {
176  (*this) = transaction_free_error(what() + std::string(": ") +
177  detail::errormsg());
178  return *this;
179  }
180 };
181 
187 class transaction_scope_error : public std::logic_error {
188 public:
189  using std::logic_error::logic_error;
190 };
191 
197 class manual_tx_abort : public std::runtime_error {
198 public:
199  using std::runtime_error::runtime_error;
200 };
201 
207 class layout_error : public std::runtime_error {
208 public:
209  using std::runtime_error::runtime_error;
210 };
211 
217 class ctl_error : public std::runtime_error {
218 public:
219  using std::runtime_error::runtime_error;
220 
221  ctl_error &
222  with_pmemobj_errormsg()
223  {
224  (*this) = ctl_error(what() + std::string(": ") +
225  detail::errormsg());
226  return *this;
227  }
228 };
229 
236 class defrag_error : public std::runtime_error {
237 public:
238  using std::runtime_error::runtime_error;
239 
240  defrag_error(pobj_defrag_result result, const std::string &msg)
241  : std::runtime_error(msg), result(result)
242  {
243  }
244 
245  defrag_error &
246  with_pmemobj_errormsg()
247  {
248  (*this) = defrag_error(result,
249  what() + std::string(": ") +
250  detail::errormsg());
251  return *this;
252  }
253 
260  pobj_defrag_result result;
261 };
262 
263 } /* namespace pmem */
264 
265 #endif /* LIBPMEMOBJ_CPP_PEXCEPTIONS_HPP */
pmem::transaction_free_error
Custom transaction error class.
Definition: pexceptions.hpp:169
pmem::pool_error
Custom pool error class.
Definition: pexceptions.hpp:74
pmem::transaction_error
Custom transaction error class.
Definition: pexceptions.hpp:92
pmem
Persistent memory namespace.
Definition: allocation_flag.hpp:44
pmem::transaction_out_of_memory
Custom out of memory error class.
Definition: pexceptions.hpp:149
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:260
pmem::lock_error
Custom lock error class.
Definition: pexceptions.hpp:111
pmem::defrag_error
Custom defrag error class.
Definition: pexceptions.hpp:236
pmem::layout_error
Custom layout error class.
Definition: pexceptions.hpp:207
pmem::transaction_scope_error
Custom transaction error class.
Definition: pexceptions.hpp:187
pmem::ctl_error
Custom ctl error class.
Definition: pexceptions.hpp:217
pmem::manual_tx_abort
Custom transaction error class.
Definition: pexceptions.hpp:197
pmem::transaction_alloc_error
Custom transaction error class.
Definition: pexceptions.hpp:130