File indexing completed on 2025-04-19 08:55:33
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include <cstdlib>
0012 #include <sstream>
0013
0014 #include "h5_wrapper.hpp"
0015 #include "h5e_wrapper.hpp"
0016
0017 namespace HighFive {
0018
0019 struct HDF5ErrMapper {
0020 template <typename ExceptionType>
0021 static inline herr_t stackWalk(unsigned n, const H5E_error2_t* err_desc, void* client_data) {
0022 auto** e_iter = static_cast<ExceptionType**>(client_data);
0023 (void) n;
0024
0025 const char* major_err = detail::nothrow::h5e_get_major(err_desc->maj_num);
0026 const char* minor_err = detail::nothrow::h5e_get_minor(err_desc->min_num);
0027
0028 std::ostringstream oss;
0029 oss << '(' << major_err << ") " << minor_err;
0030
0031 detail::nothrow::h5_free_memory((void*) major_err);
0032 detail::nothrow::h5_free_memory((void*) minor_err);
0033
0034 auto* e = new ExceptionType(oss.str());
0035 e->_err_major = err_desc->maj_num;
0036 e->_err_minor = err_desc->min_num;
0037 (*e_iter)->_next.reset(e);
0038 *e_iter = e;
0039 return 0;
0040 }
0041
0042 template <typename ExceptionType>
0043 [[noreturn]] static inline void ToException(const std::string& prefix_msg) {
0044 hid_t err_stack = H5Eget_current_stack();
0045 if (err_stack >= 0) {
0046 ExceptionType e("");
0047 ExceptionType* e_iter = &e;
0048
0049 detail::nothrow::h5e_walk2(err_stack,
0050 H5E_WALK_UPWARD,
0051 &HDF5ErrMapper::stackWalk<ExceptionType>,
0052 &e_iter);
0053 detail::nothrow::h5e_clear2(err_stack);
0054
0055 const char* next_err_msg = (e.nextException() != NULL) ? (e.nextException()->what())
0056 : ("");
0057
0058 e.setErrorMsg(prefix_msg + " " + next_err_msg);
0059 throw e;
0060 }
0061
0062 throw ExceptionType(prefix_msg + ": Unknown HDF5 error");
0063 }
0064 };
0065
0066 }