HighFive 2.10.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, const H5E_error2_t* err_desc, void* client_data) {
22 auto** e_iter = static_cast<ExceptionType**>(client_data);
23 (void) n;
24
25 const char* major_err = detail::nothrow::h5e_get_major(err_desc->maj_num);
26 const char* minor_err = detail::nothrow::h5e_get_minor(err_desc->min_num);
27
28 std::ostringstream oss;
29 oss << '(' << major_err << ") " << minor_err;
30
31 detail::nothrow::h5_free_memory((void*) major_err);
32 detail::nothrow::h5_free_memory((void*) minor_err);
33
34 auto* e = new ExceptionType(oss.str());
35 e->_err_major = err_desc->maj_num;
36 e->_err_minor = err_desc->min_num;
37 (*e_iter)->_next.reset(e);
38 *e_iter = e;
39 return 0;
40 }
41
42 template <typename ExceptionType>
43 [[noreturn]] static inline void ToException(const std::string& prefix_msg) {
45 if (err_stack >= 0) {
46 ExceptionType e("");
48
49 detail::nothrow::h5e_walk2(err_stack,
52 &e_iter);
53 detail::nothrow::h5e_clear2(err_stack);
54
55 const char* next_err_msg = (e.nextException() != NULL) ? (e.nextException()->what())
56 : ("");
57
58 e.setErrorMsg(prefix_msg + " " + next_err_msg);
59 throw e;
60 }
61 // throw generic error, unrecognized error
62 throw ExceptionType(prefix_msg + ": Unknown HDF5 error");
63 }
64};
65
66} // namespace HighFive
Definition H5_definitions.hpp:22
Definition H5Exception_misc.hpp:19
static herr_t stackWalk(unsigned n, 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:43