echelon  0.8.0
error_handling.hpp
1 // Copyright (c) 2012-2015 Christopher Hinz
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #ifndef ECHELON_HDF5_PRECURSOR_ERROR_HANDLING_HPP
7 #define ECHELON_HDF5_PRECURSOR_ERROR_HANDLING_HPP
8 
9 #include <hdf5.h>
10 #include <stdexcept>
11 #include <system_error>
12 #include <utility>
13 
14 #include <boost/assert.hpp>
15 
16 #define ECHELON_ASSERT_MSG(expr, msg) BOOST_ASSERT_MSG(expr, msg)
17 
18 #if defined(NDEBUG)
19 
20 #define ECHELON_VERIFY_MSG(expr, msg) ((void)(expr))
21 
22 #else
23 
24 #define ECHELON_VERIFY_MSG(expr, msg) ECHELON_ASSERT_MSG(expr, msg)
25 
26 #endif
27 
28 namespace echelon
29 {
30 namespace hdf5
31 {
32 namespace precursor
33 {
34 
35 class hdf5_category : public std::error_category
36 {
37 public:
38  virtual ~hdf5_category() = default;
39 
40  const char* name() const noexcept override;
41 
42  std::string message(int condition) const override;
43 };
44 
45 const std::error_category& get_hdf5_category();
46 
47 class exception : public std::system_error
48 {
49 public:
50  explicit exception(int ev_);
51 
52  explicit exception(int ev_, std::string what_);
53 
54  virtual ~exception() noexcept = default;
55 };
56 
57 class hdf5_error : public exception
58 {
59 public:
60  hdf5_error(hid_t major_num_, hid_t minor_num_);
61 
62  hdf5_error(hid_t major_num_, hid_t minor_num_, std::string what_);
63 
64  virtual ~hdf5_error() noexcept = default;
65 
66  hid_t minor_num() const;
67 
68 private:
69  hid_t minor_num_;
70 };
71 
72 class error_class
73 {
74 public:
75  explicit error_class(hid_t id_);
76 
77  ~error_class();
78 
79  error_class(const error_class&) = delete;
80  error_class(error_class&&) = default;
81 
82  error_class& operator=(const error_class&) = delete;
83  error_class& operator=(error_class&&) = default;
84 
85  hid_t id() const;
86 
87 private:
88  hid_t id_;
89 };
90 
91 class error_message
92 {
93 public:
94  explicit error_message(hid_t id_);
95 
96  error_message(const error_message&) = delete;
97  error_message(error_message&&) = default;
98 
99  error_message& operator=(const error_message&) = delete;
100  error_message& operator=(error_message&&) = default;
101 
102  ~error_message();
103 
104  hid_t id() const;
105 
106 private:
107  hid_t id_;
108 };
109 
110 const error_class& get_echelon_error_class();
111 
112 const error_message& get_unable_to_obtain_ref_msg();
113 const error_message& get_no_associated_name_msg();
114 
115 void push_error_onto_stack(const char* file, const char* func, unsigned line,
116  const error_class& err_class, const error_message& major_msg,
117  const error_message& minor_msg, const std::string& desc);
118 
119 void throw_on_hdf5_error();
120 
121 void enable_error_handling();
122 }
123 }
124 }
125 
126 #endif
echelon&#39;s core namespace
Definition: attribute.cpp:10