h5cpp 0.7.1
A modern C++ wrapper for the HDF5 C library
error.hpp
Go to the documentation of this file.
1//
2// (c) Copyright 2017 DESY,ESS
3//
4// This file is part of h5cpp.
5//
6// This library is free software; you can redistribute it and/or modify it
7// under the terms of the GNU Lesser General Public License as published
8// by the Free Software Foundation; either version 2.1 of the License, or
9// (at your option) any later version.
10//
11// This library is distributed in the hope that it will be useful, but
12// WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY
13// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14// License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public License
17// along with this library; if not, write to the
18// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor
19// Boston, MA 02110-1301 USA
20// ===========================================================================
21//
22// Author: Martin Shetty <martin.shetty@esss.se>
23// Created on: Oct 25, 2017
24//
25#pragma once
26
29
30namespace hdf5 {
31namespace error {
32
33#ifdef __clang__
34#pragma clang diagnostic push
35#pragma clang diagnostic ignored "-Wold-style-cast"
36#endif
37const decltype(H5E_DEFAULT) kDefault = H5E_DEFAULT;
38#ifdef __clang__
39#pragma clang diagnostic pop
40#endif
41
49
51{
52 public:
53
60 {
61 static Singleton singleton_instance;
62 return singleton_instance;
63 }
64
74 void auto_print(bool enable);
75
79 bool auto_print() const;
80
90
101#ifdef __clang__
102 [[ noreturn ]]
103#endif
104 void throw_with_stack(const std::string& message);
105
110
111 private:
112
113 // Singleton assurance
114 Singleton() {}
115 Singleton(Singleton const&) = delete;
116 void operator=(Singleton const&) = delete;
117
118 bool auto_print_ {true};
119
120 private:
121 // Helper functions, used internally only
122
123 // determines if automatic printing is enabled
124 // should never be used when extracting error information,
125 // as it will overwirte existing error stack contents
126 bool auto_print_enabled() const;
127
128 // extracts error stack and throws it as H5CError
129 void throw_stack();
130
131 // functor for H5EWalk
132 static herr_t to_list(unsigned n,
133 const H5E_error2_t *err_desc,
134 std::list<Descriptor>* list);
135};
136
137
149std::string DLL_EXPORT print_nested(const std::exception& exception, size_t level = 0);
150
151
152} // namespace file
153} // namespace hdf5
runtime exception containing an HDF5 error H5CError
Definition: h5c_error.hpp:48
singleton class for HDF5 error handling
Definition: error.hpp:51
void clear_stack()
clears HDF5 error stack
void auto_print(bool enable)
toggle automatic printing of error stack
static Singleton & instance()
reference to singleton
Definition: error.hpp:59
bool auto_print() const
indicates if automatic printing of error stack is on
H5CError extract_stack()
returns most recent error stack as Stack
void throw_with_stack(const std::string &message)
throws an exception, potentially nested with error stack
std::string print_nested(const std::exception &exception, size_t level=0)
indented output of nested exceptions and included error stack
const decltype(H5E_DEFAULT) kDefault
Definition: error.hpp:37
top-level namespace of the entire library
Definition: attribute.hpp:45
#define DLL_EXPORT
Definition: windows.hpp:29