21 template <
typename ExceptionType>
22 static inline herr_t stackWalk(
unsigned n,
const H5E_error2_t* err_desc,
24 auto** e_iter =
static_cast<ExceptionType**
>(client_data);
27 const char* major_err = H5Eget_major(err_desc->maj_num);
28 const char* minor_err = H5Eget_minor(err_desc->min_num);
30 std::ostringstream oss;
31 oss <<
'(' << major_err <<
") " << minor_err;
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);
41 template <
typename ExceptionType>
42 [[noreturn]]
static inline void ToException(
const std::string& prefix_msg) {
44 hid_t err_stack = H5Eget_current_stack();
47 ExceptionType* e_iter = &e;
49 H5Ewalk2(err_stack, H5E_WALK_UPWARD,
50 &HDF5ErrMapper::stackWalk<ExceptionType>, &e_iter);
53 const char* next_err_msg = (e.nextException() != NULL)
54 ? (e.nextException()->what())
57 e.setErrorMsg(prefix_msg +
" " + next_err_msg);
61 throw ExceptionType(prefix_msg +
": Unknown HDF5 error");