HighFive 2.7.1
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 <H5Epublic.h>
15
16namespace HighFive {
17
19 template <typename ExceptionType>
20 static inline herr_t stackWalk(unsigned n, const H5E_error2_t* err_desc, void* client_data) {
21 auto** e_iter = static_cast<ExceptionType**>(client_data);
22 (void) n;
23
24 const char* major_err = H5Eget_major(err_desc->maj_num);
25 const char* minor_err = H5Eget_minor(err_desc->min_num);
26
27 std::ostringstream oss;
28 oss << '(' << major_err << ") " << minor_err;
29
30 H5free_memory((void*) major_err);
31 H5free_memory((void*) minor_err);
32
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);
37 *e_iter = e;
38 return 0;
39 }
40
41 template <typename ExceptionType>
42 [[noreturn]] static inline void ToException(const std::string& prefix_msg) {
44 if (err_stack >= 0) {
45 ExceptionType e("");
47
50
51 const char* next_err_msg = (e.nextException() != NULL) ? (e.nextException()->what())
52 : ("");
53
54 e.setErrorMsg(prefix_msg + " " + next_err_msg);
55 throw e;
56 }
57 // throw generic error, unrecognized error
58 throw ExceptionType(prefix_msg + ": Unknown HDF5 error");
59 }
60};
61
62} // namespace HighFive
Definition H5_definitions.hpp:15
Definition H5Exception_misc.hpp:18
static herr_t stackWalk(unsigned n, const H5E_error2_t *err_desc, void *client_data)
Definition H5Exception_misc.hpp:20
static void ToException(const std::string &prefix_msg)
Definition H5Exception_misc.hpp:42