PMDK C++ bindings  1.8.2
This is the C++ bindings documentation for PMDK's libpmemobj.
pexceptions.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2016-2019, 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 <system_error>
43 
44 #include <libpmemobj/base.h>
45 
46 namespace pmem
47 {
48 
49 namespace detail
50 {
51 
55 inline std::string
56 errormsg(void)
57 {
58 #ifdef _WIN32
59  return std::string(pmemobj_errormsgU());
60 #else
61  return std::string(pmemobj_errormsg());
62 #endif
63 }
64 }
65 
72 class pool_error : public std::runtime_error {
73 public:
74  using std::runtime_error::runtime_error;
75 
76  pool_error &
77  with_pmemobj_errormsg()
78  {
79  (*this) = pool_error(what() + std::string(": ") +
80  detail::errormsg());
81  return *this;
82  }
83 };
84 
90 class transaction_error : public std::runtime_error {
91 public:
92  using std::runtime_error::runtime_error;
93 
95  with_pmemobj_errormsg()
96  {
97  (*this) = transaction_error(what() + std::string(": ") +
98  detail::errormsg());
99  return *this;
100  }
101 };
102 
109 class lock_error : public std::system_error {
110 public:
111  using std::system_error::system_error;
112 
113  lock_error &
114  with_pmemobj_errormsg()
115  {
116  (*this) = lock_error(code(),
117  what() + std::string(": ") +
118  detail::errormsg());
119  return *this;
120  }
121 };
122 
129 public:
130  using transaction_error::transaction_error;
131 
133  with_pmemobj_errormsg()
134  {
135  (*this) = transaction_alloc_error(what() + std::string(": ") +
136  detail::errormsg());
137  return *this;
138  }
139 };
140 
147  public std::bad_alloc {
148 public:
149  using transaction_alloc_error::transaction_alloc_error;
150  using transaction_alloc_error::what;
151 
153  with_pmemobj_errormsg()
154  {
155  (*this) = transaction_out_of_memory(
156  transaction_alloc_error::what() + std::string(": ") +
157  detail::errormsg());
158  return *this;
159  }
160 };
161 
168 public:
169  using transaction_alloc_error::transaction_alloc_error;
170 
172  with_pmemobj_errormsg()
173  {
174  (*this) = transaction_free_error(what() + std::string(": ") +
175  detail::errormsg());
176  return *this;
177  }
178 };
179 
185 class transaction_scope_error : public std::logic_error {
186 public:
187  using std::logic_error::logic_error;
188 };
189 
195 class manual_tx_abort : public std::runtime_error {
196 public:
197  using std::runtime_error::runtime_error;
198 };
199 
205 class layout_error : public std::runtime_error {
206 public:
207  using std::runtime_error::runtime_error;
208 };
209 
215 class ctl_error : public std::runtime_error {
216 public:
217  using std::runtime_error::runtime_error;
218 
219  ctl_error &
220  with_pmemobj_errormsg()
221  {
222  (*this) = ctl_error(what() + std::string(": ") +
223  detail::errormsg());
224  return *this;
225  }
226 };
227 
228 } /* namespace pmem */
229 
230 #endif /* LIBPMEMOBJ_CPP_PEXCEPTIONS_HPP */
Custom transaction error class.
Definition: pexceptions.hpp:128
Custom pool error class.
Definition: pexceptions.hpp:72
Custom transaction error class.
Definition: pexceptions.hpp:195
Custom transaction error class.
Definition: pexceptions.hpp:90
Custom layout error class.
Definition: pexceptions.hpp:205
Custom out of memory error class.
Definition: pexceptions.hpp:146
Custom lock error class.
Definition: pexceptions.hpp:109
Custom ctl error class.
Definition: pexceptions.hpp:215
std::string errormsg(void)
Return last libpmemobj error message as a std::string.
Definition: pexceptions.hpp:56
Custom transaction error class.
Definition: pexceptions.hpp:167
Custom transaction error class.
Definition: pexceptions.hpp:185
A persistent version of concurrent hash map implementation Ref: https://arxiv.org/abs/1509....
Definition: allocation_flag.hpp:43