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 #ifndef H5EXCEPTION_MISC_HPP
10 #define H5EXCEPTION_MISC_HPP
11 
12 #include "../H5Exception.hpp"
13 
14 #include <H5Epublic.h>
15 #include <cstdlib>
16 
17 namespace HighFive {
18 
19 struct HDF5ErrMapper {
20 
21  template <typename ExceptionType>
22  static inline herr_t stackWalk(unsigned n, const H5E_error2_t* err_desc,
23  void* client_data) {
24  ExceptionType** e_iter = static_cast<ExceptionType**>(client_data);
25  (void)n;
26 
27  char* major_err = H5Eget_major(err_desc->maj_num);
28  char* minor_err = H5Eget_minor(err_desc->min_num);
29 
30  std::string err_string("(");
31  err_string += major_err;
32  err_string += ") ";
33  err_string += minor_err;
34 
35  free(major_err);
36  free(minor_err);
37 
38  ExceptionType* e = new ExceptionType(err_string);
39  e->_err_major = err_desc->maj_num;
40  e->_err_minor = err_desc->min_num;
41  (*e_iter)->_next.reset(e);
42  *e_iter = e;
43  return 0;
44  }
45 
46  template <typename ExceptionType>
47  static inline void ToException(const std::string& prefix_msg) {
48 
49  hid_t err_stack = H5Eget_current_stack();
50  if (err_stack >= 0) {
51  ExceptionType e("");
52  ExceptionType* e_iter = &e;
53 
54  H5Ewalk2(err_stack, H5E_WALK_UPWARD,
55  &HDF5ErrMapper::stackWalk<ExceptionType>, &e_iter);
56  H5Eclear2(err_stack);
57 
58  const char* next_err_msg = (e.nextException() != NULL)
59  ? (e.nextException()->what())
60  : ("");
61 
62  e.setErrorMsg(prefix_msg + " " + next_err_msg);
63  throw e;
64  }
65  // throw generic error, unrecognized error
66  throw ExceptionType(prefix_msg + ": Unknown HDF5 error");
67  }
68 };
69 }
70 
71 #endif // H5OBJECT_MISC_HPP
HighFive::HDF5ErrMapper::stackWalk
static herr_t stackWalk(unsigned n, const H5E_error2_t *err_desc, void *client_data)
Definition: H5Exception_misc.hpp:22
NULL
#define NULL
Definition: mydefs.hpp:141
HighFive::HDF5ErrMapper::ToException
static void ToException(const std::string &prefix_msg)
Definition: H5Exception_misc.hpp:47
HighFive::HDF5ErrMapper
Definition: H5Exception_misc.hpp:19
HighFive
Definition: H5Annotate_traits.hpp:14


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:23