HighFive 3.0.0
HighFive - Header-only C++ HDF5 interface
Loading...
Searching...
No Matches
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#pragma once
10
11#include <cstdlib>
12#include <sstream>
13
14#include "h5_wrapper.hpp"
15#include "h5e_wrapper.hpp"
16
17namespace HighFive {
18
20 template <typename ExceptionType>
21 static inline herr_t stackWalk(unsigned /* n */,
22 const H5E_error2_t* err_desc,
23 void* client_data) {
24 auto** e_iter = static_cast<ExceptionType**>(client_data);
25
26 const char* major_err = detail::nothrow::h5e_get_major(err_desc->maj_num);
27 const char* minor_err = detail::nothrow::h5e_get_minor(err_desc->min_num);
28
29 std::ostringstream oss;
30 oss << '(' << major_err << ") " << minor_err;
31
32 detail::nothrow::h5_free_memory((void*) major_err);
33 detail::nothrow::h5_free_memory((void*) minor_err);
34
35 auto* e = new ExceptionType(oss.str());
36 e->_err_major = err_desc->maj_num;
37 e->_err_minor = err_desc->min_num;
38 (*e_iter)->_next.reset(e);
39 *e_iter = e;
40 return 0;
41 }
42
43 template <typename ExceptionType>
44 [[noreturn]] static inline void ToException(const std::string& prefix_msg) {
45 hid_t err_stack = H5Eget_current_stack();
46 if (err_stack >= 0) {
47 ExceptionType e("");
48 ExceptionType* e_iter = &e;
49
50 detail::nothrow::h5e_walk2(err_stack,
51 H5E_WALK_UPWARD,
52 &HDF5ErrMapper::stackWalk<ExceptionType>,
53 (void*) &e_iter);
54 detail::nothrow::h5e_clear2(err_stack);
55
56 const char* next_err_msg = (e.nextException() != NULL) ? (e.nextException()->what())
57 : ("");
58
59 e.setErrorMsg(prefix_msg + " " + next_err_msg);
60 throw e;
61 }
62 // throw generic error, unrecognized error
63 throw ExceptionType(prefix_msg + ": Unknown HDF5 error");
64 }
65};
66
67} // namespace HighFive
Definition assert_compatible_spaces.hpp:15
Definition H5Exception_misc.hpp:19
static herr_t stackWalk(unsigned, const H5E_error2_t *err_desc, void *client_data)
Definition H5Exception_misc.hpp:21
static void ToException(const std::string &prefix_msg)
Definition H5Exception_misc.hpp:44