【发布时间】:2014-06-03 09:02:49
【问题描述】:
我正在使用 POCO (v 1.4.6p4) 日志框架,但我在格式化字符串时遇到了一些问题:
int MyClass::MyMethod(unsigned short number) {
Logger::get("MyLog").information(Poco::format("Log a number [%u]", number));
}
我明白了:
Log a number [ERRFMT]
然后抛出 Poco::BadCastException。
挖掘源代码我注意到异常被抛出到 Any 类中:
template <typename ValueType>
ValueType AnyCast(const Any& operand)
/// AnyCast operator used to extract a copy of the ValueType from an const Any&.
///
/// Example Usage:
/// MyType tmp = AnyCast<MyType>(anAny).
/// Will throw a BadCastException if the cast fails.
/// Dont use an AnyCast in combination with references, i.e. MyType& tmp = ... or const MyType& = ...
/// Some compilers will accept this code although a copy is returned. Use the RefAnyCast in
/// these cases.
{
ValueType* result = AnyCast<ValueType>(const_cast<Any*>(&operand));
if (!result) throw BadCastException("Failed to convert between const Any types");
return *result;
}
谁能告诉我哪里错了?
【问题讨论】:
标签: c++ poco-libraries