Kea 2.7.5
exceptions/exceptions.cc
Go to the documentation of this file.
1// Copyright (C) 2009-2015 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#include <config.h>
8
9#include <string>
10#include <sstream>
12
13using isc::Exception;
14
15namespace isc {
16
17Exception::Exception(const char* file, size_t line, const char* what)
18: file_(file), line_(line), what_(what) {
19 std::stringstream location;
20 location << what_ << "[" << file_ << ":" << line_ << "]";
21 verbose_what_ = location.str();
22}
23
24Exception::Exception(const char* file, size_t line, const std::string& what)
25 : file_(file), line_(line), what_(what) {
26 std::stringstream location;
27 location << what_ << "[" << file_ << ":" << line_ << "]";
28 verbose_what_ = location.str();
29}
30
31const char*
32Exception::what() const throw() {
33 return (what(false));
34}
35
36const char*
37Exception::what(bool verbose) const throw() {
38
39 // Even though it's very unlikely that c_str() throws an exception,
40 // it's still not 100% guaranteed. To meet the exception specification
41 // of this function, we catch any unexpected exception and fall back to
42 // the pre-defined constant.
43 try {
44 if (verbose) {
45 return (verbose_what_.c_str());
46 } else {
47 return (what_.c_str());
48 }
49 } catch (...) {
50 // no exception handling is necessary. just have to catch exceptions.
51 }
52 return ("isc::Exception");
53}
54
55}
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.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Defines the logger used by the top-level component of kea-lfc.