Shapes
GIS made easy, a lightweight header-only planar geometry library for Modern C++
exceptions.hpp
1 #pragma once
2 
3 #include <ciso646>
4 #include <string>
5 #include <exception>
6 
7 namespace simo
8 {
9 namespace shapes
10 {
11 namespace exceptions
12 {
13 
19 class shapes_exception : public std::exception
20 {
21  public:
29  explicit shapes_exception(const char* reason)
30  : m_reason(reason) {}
31 
39  const char* what() const noexcept override
40  {
41  return m_reason.c_str();
42  }
43 
44  protected:
52  void set_reason(const std::string& reason)
53  {
54  m_reason.append(": ");
55  m_reason.append(reason);
56  }
57 
58  private:
59  std::string m_reason{};
60 };
61 
68 {
69  public:
77  explicit parse_error(const std::string& reason)
78  : shapes_exception("parse error")
79  {
80  set_reason(reason);
81  }
82 };
83 
90 {
91  public:
98  : shapes_exception("not implemented error")
99  {
100  }
101 
109  explicit not_implemented_error(const std::string& reason)
110  : shapes_exception("not implemented error")
111  {
112  set_reason(reason);
113  }
114 };
115 
122 {
123  public:
131  explicit geometry_error(const std::string& reason)
132  : shapes_exception("geometry error")
133  {
134  set_reason(reason);
135  }
136 };
137 
144 {
145  public:
153  explicit index_error(const std::string& reason)
154  : shapes_exception("index error")
155  {
156  set_reason(reason);
157  }
158 };
159 
160 } // namespace exceptions
161 } // namespace shapes
162 } // namespace simo
shapes_exception(const char *reason)
Creates a shapes exception.
Definition: exceptions.hpp:29
Exception thrown when a geometry error is found.
Definition: exceptions.hpp:121
Exception thrown when a sequence index is out of range.
Definition: exceptions.hpp:143
void set_reason(const std::string &reason)
Set the exception reason.
Definition: exceptions.hpp:52
const char * what() const noexceptoverride
Returns the exception reason.
Definition: exceptions.hpp:39
parse_error(const std::string &reason)
Creates a parse error with the given reason.
Definition: exceptions.hpp:77
Exception thrown when method or routine is not implemented.
Definition: exceptions.hpp:89
Exception thrown when an error has been found while parsing.
Definition: exceptions.hpp:67
not_implemented_error(const std::string &reason)
Creates a not implemented error exception.
Definition: exceptions.hpp:109
geometry_error(const std::string &reason)
Creates a geometry error exception.
Definition: exceptions.hpp:131
not_implemented_error()
Creates a not implemented error exception.
Definition: exceptions.hpp:97
index_error(const std::string &reason)
Creates a index error exception.
Definition: exceptions.hpp:153