Kea 3.3.1
exceptions/exceptions.h
Go to the documentation of this file.
1// Copyright (C) 2009-2026 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
139class FatalException : public Exception {
140public:
141 FatalException(const char* file, size_t line, const char* what) :
142 isc::Exception(file, line, what) {}
143};
144
151public:
152 InvalidOperation(const char* file, size_t line, const char* what) :
153 isc::Exception(file, line, what) {}
154};
155
160class Unexpected : public Exception {
161public:
162 Unexpected(const char* file, size_t line, const char* what) :
163 isc::Exception(file, line, what) {}
164};
165
173class NotImplemented : public Exception {
174public:
175 NotImplemented(const char* file, size_t line, const char* what) :
176 isc::Exception(file, line, what) {}
177};
178
182class NotFound : public Exception {
183public:
184 NotFound(const char* file, size_t line, const char* what) :
185 isc::Exception(file, line, what) {}
186};
187
191public:
192 MultiThreadingInvalidOperation(const char* file, size_t line, const char* what) :
193 isc::Exception(file, line, what) {}
194};
195
217#define isc_throw(type, stream) \
218 do { \
219 std::ostringstream oss__; \
220 oss__ << stream; \
221 throw type(__FILE__, __LINE__, oss__.str().c_str()); \
222 } while (1)
223
227#define isc_throw_1(type, stream, param1) \
228 do { \
229 std::ostringstream oss__; \
230 oss__ << stream; \
231 throw type(__FILE__, __LINE__, oss__.str().c_str(), param1); \
232 } while (1)
233
237#define isc_throw_2(type, stream, param1, param2) \
238 do { \
239 std::ostringstream oss__; \
240 oss__ << stream; \
241 throw type(__FILE__, __LINE__, oss__.str().c_str(), param1, param2); \
242 } while (1)
243
247#define isc_throw_3(type, stream, param1, param2, param3) \
248 do { \
249 std::ostringstream oss__; \
250 oss__ << stream; \
251 throw type(__FILE__, __LINE__, oss__.str().c_str(), param1, param2,\
252 param3); \
253 } while (1)
254
258#define isc_throw_4(type, stream, param1, param2, param3, param4) \
259 do { \
260 std::ostringstream oss__; \
261 oss__ << stream; \
262 throw type(__FILE__, __LINE__, oss__.str().c_str(), param1, param2,\
263 param3, param4); \
264 } while (1)
265
266}
267#endif // EXCEPTIONS_H
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
BadValue(const char *file, size_t line, const char *what)
This is a base class for exceptions thrown from the DNS library module.
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
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.
FatalException(const char *file, size_t line, const char *what)
InvalidOperation(const char *file, size_t line, const char *what)
InvalidParameter(const char *file, size_t line, const char *what)
MultiThreadingInvalidOperation(const char *file, size_t line, const char *what)
NotFound(const char *file, size_t line, const char *what)
NotImplemented(const char *file, size_t line, const char *what)
OutOfRange(const char *file, size_t line, const char *what)
Unexpected(const char *file, size_t line, const char *what)
Defines the logger used by the top-level component of kea-lfc.