inicpp
C++ parser of INI files with schema validation.
exception.h
1 #ifndef INICPP_EXCEPTION_H
2 #define INICPP_EXCEPTION_H
3 
4 #include <exception>
5 #include <iostream>
6 #include <string>
7 #include <vector>
8 
9 
10 namespace inicpp
11 {
15  class exception : public std::exception
16  {
17  protected:
19  std::string what_;
20 
21  public:
25  exception() : what_("Generic inicpp exception")
26  {
27  }
32  exception(const std::string &what) : what_(what)
33  {
34  }
35 
39  virtual ~exception()
40  {
41  }
42 
47  virtual const char *what() const noexcept
48  {
49  return what_.c_str();
50  }
51  };
52 
53 
57  class parser_exception : public exception
58  {
59  public:
64  parser_exception(const std::string &message) : inicpp::exception(message)
65  {
66  }
67  };
68 
69 
74  {
75  public:
80  bad_cast_exception(const std::string &message) : inicpp::exception(message)
81  {
82  }
88  bad_cast_exception(const std::string &from, const std::string &to)
89  : inicpp::exception("Bad conversion from: " + from + " to: " + to)
90  {
91  }
92  };
93 
94 
101  {
102  public:
107  not_found_exception(size_t index)
108  : inicpp::exception("Element on index: " + std::to_string(index) + " was not found")
109  {
110  }
115  not_found_exception(const std::string &element_name)
116  : inicpp::exception("Element: " + element_name + " not found in container")
117  {
118  }
119  };
120 
121 
127  {
128  public:
133  ambiguity_exception(const std::string &element_name)
134  : inicpp::exception("Ambiguous element with name: " + element_name)
135  {
136  }
137  };
138 
139 
144  {
145  public:
150  validation_exception(const std::string &message) : inicpp::exception(message)
151  {
152  }
153  };
154 
155 
160  {
161  public:
166  invalid_type_exception(const std::string &message) : inicpp::exception(message)
167  {
168  }
169  };
170 
171 
176  {
177  public:
182  {
183  }
184  };
185 }
186 
187 #endif
bad_cast_exception(const std::string &from, const std::string &to)
Definition: exception.h:88
bad_cast_exception(const std::string &message)
Definition: exception.h:80
virtual ~exception()
Definition: exception.h:39
not_found_exception(const std::string &element_name)
Definition: exception.h:115
STL namespace.
Definition: config.h:15
ambiguity_exception(const std::string &element_name)
Definition: exception.h:133
invalid_type_exception(const std::string &message)
Definition: exception.h:166
exception(const std::string &what)
Definition: exception.h:32
validation_exception(const std::string &message)
Definition: exception.h:150
not_found_exception(size_t index)
Definition: exception.h:107
std::string what_
Definition: exception.h:19
virtual const char * what() const noexcept
Definition: exception.h:47
parser_exception(const std::string &message)
Definition: exception.h:64