h5cpp  0.3.3
A modern C++ wrapper for the HDF5 C library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
27 #include <h5cpp/core/windows.hpp>
29 
30 namespace hdf5 {
31 namespace error {
32 
40 
42 {
43  public:
44 
50  static Singleton& instance()
51  {
52  static Singleton singleton_instance;
53  return singleton_instance;
54  }
55 
65  void auto_print(bool enable);
66 
70  bool auto_print() const;
71 
78  H5CError extract_stack();
79 
90  void throw_with_stack(const std::string& message);
91 
95  void clear_stack();
96 
97  private:
98 
99  // Singleton assurance
100  Singleton() {}
101  Singleton(Singleton const&) = delete;
102  void operator=(Singleton const&) = delete;
103 
104  bool auto_print_ {true};
105 
106  private:
107  // Helper functions, used internally only
108 
109  // determines if automatic printing is enabled
110  // should never be used when extracting error information,
111  // as it will overwirte existing error stack contents
112  bool auto_print_enabled() const;
113 
114  // extracts error stack and throws it as H5CError
115  void throw_stack();
116 
117  // functor for H5EWalk
118  static herr_t to_list(unsigned n,
119  const H5E_error2_t *err_desc,
120  std::list<Descriptor>* list);
121 };
122 
123 
135 std::string DLL_EXPORT print_nested(const std::exception& exception, int level = 0);
136 
137 
138 } // namespace file
139 } // namespace hdf5
std::string DLL_EXPORT print_nested(const std::exception &exception, int level=0)
indented output of nested exceptions and included error stack
static Singleton & instance()
reference to singleton
Definition: error.hpp:50
runtime exception containing an HDF5 error H5CError
Definition: h5c_error.hpp:42
Definition: attribute.hpp:43
#define DLL_EXPORT
Definition: windows.hpp:35
singleton class for HDF5 error handling
Definition: error.hpp:41