libopenraw  0.3.7
exception.hpp
1 /*
2  * libopenraw - exception.hpp
3  *
4  * Copyright (C) 2006-2021 Hubert Figuière
5  *
6  * This library is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3 of
9  * the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
21 #pragma once
22 
23 #include <exception>
24 #include <string>
25 #include <typeinfo>
26 
27 namespace OpenRaw {
28 namespace Internals {
29 
34 class Exception
35  : public std::exception
36 {
37 protected:
39  std::string m_what;
40 public:
41  Exception()
42  : std::exception(),
43  m_what()
44  {}
46  Exception(const std::string &w)
47  : std::exception(),
48  m_what(w)
49  {}
50  virtual ~Exception()
51  {}
53  const char *what() const noexcept(true) override
54  {
55  if(m_what.empty()) {
56  return typeid(this).name();
57  }
58  return m_what.c_str();
59  }
60 };
61 
64  : public Exception
65 {
66 public:
67  IOException(const std::string &w)
68  : Exception(w)
69  {}
71  const char *what() const noexcept(true) override
72  {
73  if(m_what.empty()) {
74  return typeid(this).name();
75  }
76  return m_what.c_str();
77  }
78 };
79 
80 
83  : public Exception
84 {
85 public:
87  const char *what() const noexcept(true) override
88  {
89  if(m_what.empty()) {
90  return typeid(this).name();
91  }
92  return m_what.c_str();
93  }
94 };
95 
98  : public Exception
99 {
100 public:
102  const char *what() const noexcept(true) override
103  {
104  if(m_what.empty()) {
105  return typeid(this).name();
106  }
107  return m_what.c_str();
108  }
109 };
110 
113  : public Exception
114 {
115 public:
117  const char *what() const noexcept(true) override
118  {
119  if(m_what.empty()) {
120  return typeid(this).name();
121  }
122  return m_what.c_str();
123  }
124 };
125 
128  : public Exception
129 {
130 public:
131  DecodingException(const std::string &w)
132  : Exception(w)
133  {}
135  const char *what() const noexcept(true) override
136  {
137  if(m_what.empty()) {
138  return typeid(this).name();
139  }
140  return m_what.c_str();
141  }
142 };
143 
145 }
146 }
147 
148 /*
149  Local Variables:
150  mode:c++
151  c-file-style:"stroustrup"
152  c-file-offsets:((innamespace . 0))
153  tab-width:2
154  c-basic-offset:2
155  indent-tabs-mode:nil
156  fill-column:80
157  End:
158 */
Generic OpenRaw exception.
Definition: exception.hpp:36
Exception(const std::string &w)
Construct an exception with a message strings.
Definition: exception.hpp:46
std::string m_what
Exception error string.
Definition: exception.hpp:39
const char * what() const noexcept(true) override
the std::exception::what() override
Definition: exception.hpp:53
Global namespace for libopenraw.
Definition: arwfile.cpp:29