Kea 1.5.0
exceptions/exceptions.h
Go to the documentation of this file.
1// Copyright (C) 2009-2015,2017 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef EXCEPTIONS_H
8#define EXCEPTIONS_H 1
9
10#include <stdexcept>
11#include <string>
12#include <sstream>
13
14namespace isc {
15
23class Exception : public std::exception {
24public:
28
29
35 Exception(const char* file, size_t line, const char* what);
36
43 Exception(const char* file, size_t line, const std::string& what);
44
46 virtual ~Exception() throw() {}
48private:
52 void operator=(const Exception& src);
53
54public:
58
59
65 virtual const char* what() const throw();
66
75 virtual const char* what(bool verbose) const throw();
77
81
82
85 const std::string& getMessage() const { return (what_); }
86
90 const char* getFile() const { return (file_); }
91
95 size_t getLine() const { return (line_); }
97
98private:
99
101 const char* const file_;
102
104 size_t line_;
105
107 const std::string what_;
108
110 std::string verbose_what_;
111};
112
115class OutOfRange : public Exception {
116public:
117 OutOfRange(const char* file, size_t line, const char* what) :
118 isc::Exception(file, line, what) {}
119};
120
125public:
126 InvalidParameter(const char* file, size_t line, const char* what) :
127 isc::Exception(file, line, what) {}
128};
129
132class BadValue : public Exception {
133public:
134 BadValue(const char* file, size_t line, const char* what) :
135 isc::Exception(file, line, what) {}
136};
137
144public:
145 InvalidOperation(const char* file, size_t line, const char* what) :
146 isc::Exception(file, line, what) {}
147};
148
153class Unexpected : public Exception {
154public:
155 Unexpected(const char* file, size_t line, const char* what) :
156 isc::Exception(file, line, what) {}
157};
158
165class NotImplemented : public Exception {
166public:
167 NotImplemented(const char* file, size_t line, const char* what) :
168 isc::Exception(file, line, what) {}
169};
170
192#define isc_throw(type, stream) \
193 do { \
194 std::ostringstream oss__; \
195 oss__ << stream; \
196 throw type(__FILE__, __LINE__, oss__.str().c_str()); \
197 } while (1)
198
202#define isc_throw_1(type, stream, param1) \
203 do { \
204 std::ostringstream oss__; \
205 oss__ << stream; \
206 throw type(__FILE__, __LINE__, oss__.str().c_str(), param1); \
207 } while (1)
208
212#define isc_throw_2(type, stream, param1, param2) \
213 do { \
214 std::ostringstream oss__; \
215 oss__ << stream; \
216 throw type(__FILE__, __LINE__, oss__.str().c_str(), param1, param2); \
217 } while (1)
218
222#define isc_throw_3(type, stream, param1, param2, param3) \
223 do { \
224 std::ostringstream oss__; \
225 oss__ << stream; \
226 throw type(__FILE__, __LINE__, oss__.str().c_str(), param1, param2,\
227 param3); \
228 } while (1)
229
233#define isc_throw_4(type, stream, param1, param2, param3, param4) \
234 do { \
235 std::ostringstream oss__; \
236 oss__ << stream; \
237 throw type(__FILE__, __LINE__, oss__.str().c_str(), param1, param2,\
238 param3, param4); \
239 } while (1)
240
241}
242#endif // EXCEPTIONS_H
243
244// Local Variables:
245// mode: c++
246// End:
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
BadValue(const char *file, size_t line, const char *what)
This is a base class for exceptions thrown from the DNS library module.
const char * getFile() const
Gets the file name where the exception was thrown.
virtual ~Exception()
The destructor.
const std::string & getMessage() const
Gets a string describing the cause of the exception.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
size_t getLine() const
Gets the line number of the file where the exception was thrown.
A generic exception that is thrown if a function is called in a prohibited way.
InvalidOperation(const char *file, size_t line, const char *what)
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
InvalidParameter(const char *file, size_t line, const char *what)
A generic exception that is thrown when a function is not implemented.
NotImplemented(const char *file, size_t line, const char *what)
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
OutOfRange(const char *file, size_t line, const char *what)
A generic exception that is thrown when an unexpected error condition occurs.
Unexpected(const char *file, size_t line, const char *what)
Defines the logger used by the top-level component of kea-dhcp-ddns.