9 #ifndef H5EXCEPTION_MISC_HPP
10 #define H5EXCEPTION_MISC_HPP
12 #include "../H5Exception.hpp"
14 #include <H5Epublic.h>
21 template <
typename ExceptionType>
22 static inline herr_t
stackWalk(
unsigned n,
const H5E_error2_t* err_desc,
24 ExceptionType** e_iter =
static_cast<ExceptionType**
>(client_data);
27 char* major_err = H5Eget_major(err_desc->maj_num);
28 char* minor_err = H5Eget_minor(err_desc->min_num);
30 std::string err_string(
"(");
31 err_string += major_err;
33 err_string += minor_err;
38 ExceptionType* e =
new ExceptionType(err_string);
39 e->_err_major = err_desc->maj_num;
40 e->_err_minor = err_desc->min_num;
41 (*e_iter)->_next.reset(e);
46 template <
typename ExceptionType>
47 static inline void ToException(
const std::string& prefix_msg) {
49 hid_t err_stack = H5Eget_current_stack();
52 ExceptionType* e_iter = &e;
54 H5Ewalk2(err_stack, H5E_WALK_UPWARD,
55 &HDF5ErrMapper::stackWalk<ExceptionType>, &e_iter);
58 const char* next_err_msg = (e.nextException() !=
NULL)
59 ? (e.nextException()->what())
62 e.setErrorMsg(prefix_msg +
" " + next_err_msg);
66 throw ExceptionType(prefix_msg +
": Unknown HDF5 error");
71 #endif // H5OBJECT_MISC_HPP