BIND 10 trac1025, updated. 7c7238ca556654cd2a0483dab5e7478fa7956a88 [trac1025] Handle possible bad_lexical_cast exception in Formatter::arg()
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Jul 7 10:39:52 UTC 2011
The branch, trac1025 has been updated
via 7c7238ca556654cd2a0483dab5e7478fa7956a88 (commit)
from 78763269e5388263ad29b02049fa61c62829dbe8 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 7c7238ca556654cd2a0483dab5e7478fa7956a88
Author: Stephen Morris <stephen at isc.org>
Date: Thu Jul 7 11:38:39 2011 +0100
[trac1025] Handle possible bad_lexical_cast exception in Formatter::arg()
-----------------------------------------------------------------------
Summary of changes:
src/lib/log/log_formatter.h | 32 +++++++++++++++++++++++++++++++-
src/lib/log/tests/Makefile.am | 2 ++
2 files changed, 33 insertions(+), 1 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/log/log_formatter.h b/src/lib/log/log_formatter.h
index 11dec84..ca23844 100644
--- a/src/lib/log/log_formatter.h
+++ b/src/lib/log/log_formatter.h
@@ -18,12 +18,28 @@
#include <cstddef>
#include <string>
#include <iostream>
+
+#include <exceptions/exceptions.h>
#include <boost/lexical_cast.hpp>
#include <log/logger_level.h>
namespace isc {
namespace log {
+/// \brief Format Failure
+///
+/// This exception is used to wrap a bad_lexical_cast exception thrown during
+/// formatting an argument.
+
+class FormatFailure : public isc::Exception {
+public:
+ FormatFailure(const char* file, size_t line, const char* what) :
+ isc::Exception(file, line, what)
+ {}
+};
+
+
+///
/// \brief The internal replacement routine
///
/// This is used internally by the Formatter. Replaces a placeholder
@@ -156,7 +172,21 @@ public:
/// \param arg The argument to place into the placeholder.
template<class Arg> Formatter& arg(const Arg& value) {
if (logger_) {
- return (arg(boost::lexical_cast<std::string>(value)));
+ try {
+ return (arg(boost::lexical_cast<std::string>(value)));
+ } catch (const boost::bad_lexical_cast& ex) {
+
+ // A bad_lexical_cast during a conversion to a string is
+ // *extremely* unlikely to fail. However, there is nothing
+ // in the documentation that rules it out, so we need to handle
+ // it. As it is a potentially very serious problem, throw the
+ // exception detailing the problem with as much information as
+ // we can. (Note that this does not include 'value' -
+ // boost::lexical_cast failed to convert it to a string, so an
+ // attempt to do so here would probably fail as well.)
+ isc_throw(FormatFailure, "bad_lexical_cast in call to "
+ "Formatter::arg(): " << ex.what());
+ }
} else {
return (*this);
}
diff --git a/src/lib/log/tests/Makefile.am b/src/lib/log/tests/Makefile.am
index 6159d63..069a7b4 100644
--- a/src/lib/log/tests/Makefile.am
+++ b/src/lib/log/tests/Makefile.am
@@ -51,6 +51,7 @@ logger_example_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
logger_example_LDFLAGS = $(AM_LDFLAGS) $(LOG4CPLUS_LDFLAGS)
logger_example_LDADD = $(top_builddir)/src/lib/log/liblog.la
logger_example_LDADD += $(top_builddir)/src/lib/util/libutil.la
+logger_example_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
check_PROGRAMS += init_logger_test
init_logger_test_SOURCES = init_logger_test.cc
@@ -58,6 +59,7 @@ init_logger_test_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
init_logger_test_LDFLAGS = $(AM_LDFLAGS) $(LOG4CPLUS_LDFLAGS)
init_logger_test_LDADD = $(top_builddir)/src/lib/log/liblog.la
init_logger_test_LDADD += $(top_builddir)/src/lib/util/libutil.la
+init_logger_test_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
noinst_PROGRAMS = $(TESTS)
More information about the bind10-changes
mailing list