Kea: exceptions.h Source File

| Kea 2.2.0

exceptions/exceptions.h
Go to the documentation of this file.
1// Copyright (C) 2009-2021 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
23 class 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
115 class OutOfRange : public Exception {
116public:
117 OutOfRange(const char* file, size_t line, const char* what) :
118 isc::Exception(file, line, what) {}
119};
120
124 class InvalidParameter : public Exception {
125public:
126 InvalidParameter(const char* file, size_t line, const char* what) :
127 isc::Exception(file, line, what) {}
128};
129
132 class BadValue : public Exception {
133public:
134 BadValue(const char* file, size_t line, const char* what) :
135 isc::Exception(file, line, what) {}
136};
137
143 class InvalidOperation : public Exception {
144public:
145 InvalidOperation(const char* file, size_t line, const char* what) :
146 isc::Exception(file, line, what) {}
147};
148
153 class Unexpected : public Exception {
154public:
155 Unexpected(const char* file, size_t line, const char* what) :
156 isc::Exception(file, line, what) {}
157};
158
166 class NotImplemented : public Exception {
167public:
168 NotImplemented(const char* file, size_t line, const char* what) :
169 isc::Exception(file, line, what) {}
170};
171
175 class NotFound : public Exception {
176public:
177 NotFound(const char* file, size_t line, const char* what) :
178 isc::Exception(file, line, what) {}
179};
180
183 class MultiThreadingInvalidOperation : public Exception {
184public:
185 MultiThreadingInvalidOperation(const char* file, size_t line, const char* what) :
186 isc::Exception(file, line, what) {};
187};
188
210#define isc_throw(type, stream) \
211 do { \
212 std::ostringstream oss__; \
213 oss__ << stream; \
214 throw type(__FILE__, __LINE__, oss__.str().c_str()); \
215 } while (1)
216
220#define isc_throw_1(type, stream, param1) \
221 do { \
222 std::ostringstream oss__; \
223 oss__ << stream; \
224 throw type(__FILE__, __LINE__, oss__.str().c_str(), param1); \
225 } while (1)
226
230#define isc_throw_2(type, stream, param1, param2) \
231 do { \
232 std::ostringstream oss__; \
233 oss__ << stream; \
234 throw type(__FILE__, __LINE__, oss__.str().c_str(), param1, param2); \
235 } while (1)
236
240#define isc_throw_3(type, stream, param1, param2, param3) \
241 do { \
242 std::ostringstream oss__; \
243 oss__ << stream; \
244 throw type(__FILE__, __LINE__, oss__.str().c_str(), param1, param2,\
245 param3); \
246 } while (1)
247
251#define isc_throw_4(type, stream, param1, param2, param3, param4) \
252 do { \
253 std::ostringstream oss__; \
254 oss__ << stream; \
255 throw type(__FILE__, __LINE__, oss__.str().c_str(), param1, param2,\
256 param3, param4); \
257 } while (1)
258
259}
260#endif // EXCEPTIONS_H
261
262// Local Variables:
263// mode: c++
264// End:
isc::BadValue
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Definition: exceptions/exceptions.h:132
isc::BadValue::BadValue
BadValue(const char *file, size_t line, const char *what)
Definition: exceptions/exceptions.h:134
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition: exceptions/exceptions.h:23
isc::Exception::Exception
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
Definition: exceptions/exceptions.cc:17
isc::Exception::getFile
const char * getFile() const
Gets the file name where the exception was thrown.
Definition: exceptions/exceptions.h:90
isc::Exception::~Exception
virtual ~Exception()
The destructor.
Definition: exceptions/exceptions.h:46
isc::Exception::getMessage
const std::string & getMessage() const
Gets a string describing the cause of the exception.
Definition: exceptions/exceptions.h:85
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition: exceptions/exceptions.cc:32
isc::Exception::getLine
size_t getLine() const
Gets the line number of the file where the exception was thrown.
Definition: exceptions/exceptions.h:95
isc::InvalidOperation
A generic exception that is thrown if a function is called in a prohibited way.
Definition: exceptions/exceptions.h:143
isc::InvalidOperation::InvalidOperation
InvalidOperation(const char *file, size_t line, const char *what)
Definition: exceptions/exceptions.h:145
isc::InvalidParameter
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
Definition: exceptions/exceptions.h:124
isc::InvalidParameter::InvalidParameter
InvalidParameter(const char *file, size_t line, const char *what)
Definition: exceptions/exceptions.h:126
isc::MultiThreadingInvalidOperation
Exception thrown when a worker thread is trying to stop or pause the respective thread pool (which wo...
Definition: exceptions/exceptions.h:183
isc::MultiThreadingInvalidOperation::MultiThreadingInvalidOperation
MultiThreadingInvalidOperation(const char *file, size_t line, const char *what)
Definition: exceptions/exceptions.h:185
isc::NotFound
A generic exception that is thrown when an object can not be found.
Definition: exceptions/exceptions.h:175
isc::NotFound::NotFound
NotFound(const char *file, size_t line, const char *what)
Definition: exceptions/exceptions.h:177
isc::NotImplemented
A generic exception that is thrown when a function is not implemented.
Definition: exceptions/exceptions.h:166
isc::NotImplemented::NotImplemented
NotImplemented(const char *file, size_t line, const char *what)
Definition: exceptions/exceptions.h:168
isc::OutOfRange
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
Definition: exceptions/exceptions.h:115
isc::OutOfRange::OutOfRange
OutOfRange(const char *file, size_t line, const char *what)
Definition: exceptions/exceptions.h:117
isc::Unexpected
A generic exception that is thrown when an unexpected error condition occurs.
Definition: exceptions/exceptions.h:153
isc::Unexpected::Unexpected
Unexpected(const char *file, size_t line, const char *what)
Definition: exceptions/exceptions.h:155
isc
Defines the logger used by the top-level component of kea-lfc.
Definition: agent_parser.cc:143