mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-29 13:07:50 +00:00
[master] Merge branch 'trac4025' ExceptionTest.verbose fail fix
This commit is contained in:
commit
43d2f496e2
@ -13,13 +13,27 @@
|
|||||||
// PERFORMANCE OF THIS SOFTWARE.
|
// PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
#include <exceptions/exceptions.h>
|
#include <exceptions/exceptions.h>
|
||||||
|
|
||||||
using isc::Exception;
|
using isc::Exception;
|
||||||
|
|
||||||
namespace isc {
|
namespace isc {
|
||||||
|
|
||||||
|
Exception::Exception(const char* file, size_t line, const char* what)
|
||||||
|
: file_(file), line_(line), what_(what) {
|
||||||
|
std::stringstream location;
|
||||||
|
location << what_ << "[" << file_ << ":" << line_ << "]";
|
||||||
|
verbose_what_ = location.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
Exception::Exception(const char* file, size_t line, const std::string& what)
|
||||||
|
: file_(file), line_(line), what_(what) {
|
||||||
|
std::stringstream location;
|
||||||
|
location << what_ << "[" << file_ << ":" << line_ << "]";
|
||||||
|
verbose_what_ = location.str();
|
||||||
|
}
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
Exception::what() const throw() {
|
Exception::what() const throw() {
|
||||||
return (what(false));
|
return (what(false));
|
||||||
@ -28,25 +42,20 @@ Exception::what() const throw() {
|
|||||||
const char*
|
const char*
|
||||||
Exception::what(bool verbose) const throw() {
|
Exception::what(bool verbose) const throw() {
|
||||||
|
|
||||||
const char* whatstr = "isc::Exception";
|
// Even though it's very unlikely that c_str() throws an exception,
|
||||||
|
|
||||||
// XXX: Even though it's very unlikely that c_str() throws an exception,
|
|
||||||
// it's still not 100% guaranteed. To meet the exception specification
|
// it's still not 100% guaranteed. To meet the exception specification
|
||||||
// of this function, we catch any unexpected exception and fall back to
|
// of this function, we catch any unexpected exception and fall back to
|
||||||
// the pre-defined constant.
|
// the pre-defined constant.
|
||||||
try {
|
try {
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
static std::stringstream location;
|
return (verbose_what_.c_str());
|
||||||
location.str("");
|
|
||||||
location << what_ << "[" << file_ << ":" << line_ << "]";
|
|
||||||
whatstr = location.str().c_str();
|
|
||||||
} else {
|
} else {
|
||||||
whatstr = what_.c_str();
|
return (what_.c_str());
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
// no exception handling is necessary. just have to catch exceptions.
|
// no exception handling is necessary. just have to catch exceptions.
|
||||||
}
|
}
|
||||||
return (whatstr);
|
return ("isc::Exception");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,7 @@ public:
|
|||||||
/// @param file the file name where the exception was thrown.
|
/// @param file the file name where the exception was thrown.
|
||||||
/// @param line the line in \a file where the exception was thrown.
|
/// @param line the line in \a file where the exception was thrown.
|
||||||
/// @param what a description (type) of the exception.
|
/// @param what a description (type) of the exception.
|
||||||
Exception(const char* file, size_t line, const char* what) :
|
Exception(const char* file, size_t line, const char* what);
|
||||||
file_(file), line_(line), what_(what) {}
|
|
||||||
|
|
||||||
/// \brief Constructor for a given type for exceptions with file name and
|
/// \brief Constructor for a given type for exceptions with file name and
|
||||||
/// file line number.
|
/// file line number.
|
||||||
@ -49,8 +48,7 @@ public:
|
|||||||
/// @param file the file name where the exception was thrown.
|
/// @param file the file name where the exception was thrown.
|
||||||
/// @param line the line in \a file where the exception was thrown.
|
/// @param line the line in \a file where the exception was thrown.
|
||||||
/// @param what a description (type) of the exception.
|
/// @param what a description (type) of the exception.
|
||||||
Exception(const char* file, size_t line, const std::string& what) :
|
Exception(const char* file, size_t line, const std::string& what);
|
||||||
file_(file), line_(line), what_(what) {}
|
|
||||||
|
|
||||||
/// The destructor
|
/// The destructor
|
||||||
virtual ~Exception() throw() {}
|
virtual ~Exception() throw() {}
|
||||||
@ -106,9 +104,18 @@ public:
|
|||||||
//@}
|
//@}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
/// Specifies the filename where this exception was raised
|
||||||
const char* const file_;
|
const char* const file_;
|
||||||
|
|
||||||
|
/// Specifies the line number where this exception was raised
|
||||||
size_t line_;
|
size_t line_;
|
||||||
|
|
||||||
|
/// Specifies actual content of the exception
|
||||||
const std::string what_;
|
const std::string what_;
|
||||||
|
|
||||||
|
/// Specifies actual context of the exception (with file:line added)
|
||||||
|
std::string verbose_what_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \brief A generic exception that is thrown if a parameter given
|
/// \brief A generic exception that is thrown if a parameter given
|
||||||
|
Loading…
x
Reference in New Issue
Block a user