Browse Source

[trac542] Remove typeid from exception caught message

On some compilers, use of typeid() requires that RTTI is explicitly
specified on the compiler command line.  For an isc::Exception message,
the file and line number will identify the exception.  For a message
output caused by std::exception, the what() should identify the exception.
Stephen Morris 14 years ago
parent
commit
cba6db1c8d

+ 1 - 0
src/lib/util/io/tests/Makefile.am

@@ -20,6 +20,7 @@ run_unittests_LDADD = $(GTEST_LDADD)
 run_unittests_LDADD += $(top_builddir)/src/lib/util/io/libutil_io.la
 run_unittests_LDADD += \
 	$(top_builddir)/src/lib/util/unittests/libutil_unittests.la
+run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
 endif
 
 noinst_PROGRAMS = $(TESTS)

+ 2 - 2
src/lib/util/unittests/Makefile.am

@@ -8,7 +8,7 @@ libutil_unittests_la_SOURCES += run_all.h run_all.cc
 libutil_unittests_la_SOURCES += testdata.h testdata.cc
 libutil_unittests_la_SOURCES += textdata.h
 
-libutil_unittests_ls_LDADD  = $(top_builddir)/src/lib/util/io/libutil_io.la
-libutil_unittests_ls_LDADD += $(top_builddir)/src/lib/util/libutil.la
+libutil_unittests_la_LIBADD  = $(top_builddir)/src/lib/util/libutil.la
+libutil_unittests_la_LIBADD  = $(top_builddir)/src/lib/exceptions/libexceptions.la
 
 CLEANFILES = *.gcno *.gcda

+ 9 - 9
src/lib/util/unittests/run_all.cc

@@ -33,17 +33,17 @@ run_all() {
         try {
             ret = RUN_ALL_TESTS();
         } catch (const isc::Exception& ex) {
-             std::cerr << "*** isc::exception of class '" << typeid(ex).name()
-                          << "' was thrown:\n"
-                       << "    file: " << ex.getFile() << "\n"
-                       << "    line: " << ex.getLine() << "\n"
-                       << "    what: " << ex.what() << std::endl;
+            // Could output more information with typeid(), but there is no
+            // guarantee that all compilers will support it without an explicit
+            // flag on the command line.
+            std::cerr << "*** Exception derived from isc::exception thrown:\n"
+                      << "    file: " << ex.getFile() << "\n"
+                      << "    line: " << ex.getLine() << "\n"
+                      << "    what: " << ex.what() << std::endl;
             throw;
         } catch (const std::exception& ex) {
-             std::cerr << "*** std::exception of class '"
-                          << typeid(ex).name()
-                          << "' was thrown:\n"
-                       << "    what: " << ex.what() << std::endl;
+            std::cerr << "*** Exception derived from std::exception thrown:\n"
+                      << "    what: " << ex.what() << std::endl;
             throw;
         }
     } else {