summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/include/Ice/LoggerUtil.h52
-rw-r--r--cpp/src/Ice/LoggerUtil.cpp14
-rw-r--r--cpp/test/Ice/exceptions/AllTests.cpp55
3 files changed, 100 insertions, 21 deletions
diff --git a/cpp/include/Ice/LoggerUtil.h b/cpp/include/Ice/LoggerUtil.h
index c5576e1e0b2..1414bb37f03 100644
--- a/cpp/include/Ice/LoggerUtil.h
+++ b/cpp/include/Ice/LoggerUtil.h
@@ -13,6 +13,7 @@
#include <Ice/Logger.h>
#include <Ice/CommunicatorF.h>
#include <Ice/Plugin.h>
+#include <Ice/Exception.h>
namespace Ice
{
@@ -30,24 +31,61 @@ private:
std::ostringstream _str;
};
+ICE_API LoggerOutputBase& loggerInsert(LoggerOutputBase& out, const IceUtil::Exception& ex);
+
+template<typename T>
+struct IsException
+{
+ static char test(IceUtil::Exception*);
+ static long test(...);
+
+ static const bool value = sizeof(test(static_cast<T*>(0))) == sizeof(char);
+};
+
+template<typename T, bool = false>
+struct LoggerOutputInserter
+{
+ static inline LoggerOutputBase&
+ insert(LoggerOutputBase& out, const T& val)
+ {
+ out.__str() << val;
+ return out;
+ }
+};
+
+// Partial specialization
+template<typename T>
+struct LoggerOutputInserter<T, true>
+{
+ static inline LoggerOutputBase&
+ insert(LoggerOutputBase& out, const T& ex)
+ {
+ return loggerInsert(out, ex);
+ }
+};
+
template<typename T>
inline LoggerOutputBase&
operator<<(LoggerOutputBase& out, const T& val)
{
- out.__str() << val;
- return out;
+ return LoggerOutputInserter<T, IsException<T>::value>::insert(out, val);
}
-template<class Y>
-LoggerOutputBase&
-operator<<(LoggerOutputBase& os, ::IceInternal::ProxyHandle<Y> p)
+template<typename T>
+inline LoggerOutputBase&
+operator<<(LoggerOutputBase& os, const ::IceInternal::ProxyHandle<T>& p)
{
return os << (p ? p->ice_toString() : "");
}
-ICE_API LoggerOutputBase& operator<<(LoggerOutputBase&, std::ios_base& (*)(std::ios_base&));
-ICE_API LoggerOutputBase& operator<<(LoggerOutputBase&, const ::std::exception& ex);
+inline LoggerOutputBase&
+operator<<(LoggerOutputBase& out, const ::std::exception& ex)
+{
+ out.__str() << ex.what();
+ return out;
+}
+ICE_API LoggerOutputBase& operator<<(LoggerOutputBase&, std::ios_base& (*)(std::ios_base&));
template<class L, class LPtr, void (L::*output)(const std::string&)>
class LoggerOutput : public LoggerOutputBase
diff --git a/cpp/src/Ice/LoggerUtil.cpp b/cpp/src/Ice/LoggerUtil.cpp
index 9f1e85accb4..00b79a6845c 100644
--- a/cpp/src/Ice/LoggerUtil.cpp
+++ b/cpp/src/Ice/LoggerUtil.cpp
@@ -43,18 +43,16 @@ Ice::operator<<(Ice::LoggerOutputBase& out, ios_base& (*val)(ios_base&))
}
Ice::LoggerOutputBase&
-Ice::operator<<(Ice::LoggerOutputBase& out, const std::exception& ex)
+Ice::loggerInsert(Ice::LoggerOutputBase& out, const IceUtil::Exception& ex)
{
if(IceUtilInternal::printStackTraces)
{
- const ::IceUtil::Exception* exception = dynamic_cast<const ::IceUtil::Exception*>(&ex);
- if(exception)
- {
- out.__str() << exception->what() << '\n' << exception->ice_stackTrace();
- return out;
- }
+ out.__str() << ex.what() << '\n' << ex.ice_stackTrace();
+ }
+ else
+ {
+ out.__str() << ex.what();
}
- out.__str() << ex.what();
return out;
}
diff --git a/cpp/test/Ice/exceptions/AllTests.cpp b/cpp/test/Ice/exceptions/AllTests.cpp
index 5432ff35ee0..36a55f54c49 100644
--- a/cpp/test/Ice/exceptions/AllTests.cpp
+++ b/cpp/test/Ice/exceptions/AllTests.cpp
@@ -14,6 +14,12 @@
using namespace std;
using namespace Test;
+namespace
+{
+const bool printException = false;
+}
+
+
class EmptyI : virtual public Empty
{
};
@@ -482,8 +488,13 @@ allTests(const Ice::CommunicatorPtr& communicator)
first = communicator->createObjectAdapter("TestAdapter0");
test(false);
}
- catch(const Ice::InitializationException&)
+ catch(const Ice::InitializationException& ex)
{
+ if(printException)
+ {
+ Ice::Print printer(communicator->getLogger());
+ printer << ex;
+ }
// Expected
}
@@ -494,8 +505,14 @@ allTests(const Ice::CommunicatorPtr& communicator)
Ice::ObjectAdapterPtr second = communicator->createObjectAdapter("TestAdapter0");
test(false);
}
- catch(const Ice::AlreadyRegisteredException&)
+ catch(const Ice::AlreadyRegisteredException& ex)
{
+ if(printException)
+ {
+ Ice::Print printer(communicator->getLogger());
+ printer << ex;
+ }
+
// Expected
}
@@ -505,8 +522,14 @@ allTests(const Ice::CommunicatorPtr& communicator)
communicator->createObjectAdapterWithEndpoints("TestAdapter0", "ssl -h foo -p 12011");
test(false);
}
- catch(const Ice::AlreadyRegisteredException&)
+ catch(const Ice::AlreadyRegisteredException& ex)
{
+ if(printException)
+ {
+ Ice::Print printer(communicator->getLogger());
+ printer << ex;
+ }
+
// Expected.
}
first->deactivate();
@@ -524,8 +547,13 @@ allTests(const Ice::CommunicatorPtr& communicator)
adapter->add(obj, communicator->stringToIdentity("x"));
test(false);
}
- catch(const Ice::AlreadyRegisteredException&)
+ catch(const Ice::AlreadyRegisteredException& ex)
{
+ if(printException)
+ {
+ Ice::Print printer(communicator->getLogger());
+ printer << ex;
+ }
}
try
@@ -535,14 +563,24 @@ allTests(const Ice::CommunicatorPtr& communicator)
catch(const Ice::IllegalIdentityException& ex)
{
test(ex.id.name == "");
+ if(printException)
+ {
+ Ice::Print printer(communicator->getLogger());
+ printer << ex;
+ }
}
try
{
adapter->add(0, communicator->stringToIdentity("x"));
}
- catch(const Ice::IllegalServantException&)
+ catch(const Ice::IllegalServantException& ex)
{
+ if(printException)
+ {
+ Ice::Print printer(communicator->getLogger());
+ printer << ex;
+ }
}
@@ -552,8 +590,13 @@ allTests(const Ice::CommunicatorPtr& communicator)
adapter->remove(communicator->stringToIdentity("x"));
test(false);
}
- catch(const Ice::NotRegisteredException&)
+ catch(const Ice::NotRegisteredException& ex)
{
+ if(printException)
+ {
+ Ice::Print printer(communicator->getLogger());
+ printer << ex;
+ }
}
adapter->deactivate();