hops
H5Exception_misc.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c), 2017, Adrien Devresse <adrien.devresse@epfl.ch>
3  *
4  * Distributed under the Boost Software License, Version 1.0.
5  * (See accompanying file LICENSE_1_0.txt or copy at
6  * http://www.boost.org/LICENSE_1_0.txt)
7  *
8  */
9 #ifndef H5EXCEPTION_MISC_HPP
10 #define H5EXCEPTION_MISC_HPP
11 
12 #include <cstdlib>
13 #include <sstream>
14 
15 #include <H5Epublic.h>
16 
17 namespace HighFive {
18 
19 struct HDF5ErrMapper {
20 
21  template <typename ExceptionType>
22  static inline herr_t stackWalk(unsigned n, const H5E_error2_t* err_desc,
23  void* client_data) {
24  auto** e_iter = static_cast<ExceptionType**>(client_data);
25  (void)n;
26 
27  const char* major_err = H5Eget_major(err_desc->maj_num);
28  const char* minor_err = H5Eget_minor(err_desc->min_num);
29 
30  std::ostringstream oss;
31  oss << '(' << major_err << ") " << minor_err;
32 
33  auto* e = new ExceptionType(oss.str());
34  e->_err_major = err_desc->maj_num;
35  e->_err_minor = err_desc->min_num;
36  (*e_iter)->_next.reset(e);
37  *e_iter = e;
38  return 0;
39  }
40 
41  template <typename ExceptionType>
42  [[noreturn]] static inline void ToException(const std::string& prefix_msg) {
43 
44  hid_t err_stack = H5Eget_current_stack();
45  if (err_stack >= 0) {
46  ExceptionType e("");
47  ExceptionType* e_iter = &e;
48 
49  H5Ewalk2(err_stack, H5E_WALK_UPWARD,
50  &HDF5ErrMapper::stackWalk<ExceptionType>, &e_iter);
51  H5Eclear2(err_stack);
52 
53  const char* next_err_msg = (e.nextException() != NULL)
54  ? (e.nextException()->what())
55  : ("");
56 
57  e.setErrorMsg(prefix_msg + " " + next_err_msg);
58  throw e;
59  }
60  // throw generic error, unrecognized error
61  throw ExceptionType(prefix_msg + ": Unknown HDF5 error");
62  }
63 };
64 
65 } // namespace HighFive
66 
67 #endif // H5OBJECT_MISC_HPP
HighFive::HDF5ErrMapper::stackWalk
static herr_t stackWalk(unsigned n, const H5E_error2_t *err_desc, void *client_data)
Definition: H5Exception_misc.hpp:22
HighFive::HDF5ErrMapper::ToException
static void ToException(const std::string &prefix_msg)
Definition: H5Exception_misc.hpp:42
string
NAME string(REPLACE ".cpp" "_bin" example_name ${example_filename}) if($
Definition: hops/Third-party/HighFive/src/examples/CMakeLists.txt:6
HighFive::HDF5ErrMapper
Definition: H5Exception_misc.hpp:19
HighFive
Definition: H5_definitions.hpp:15