fixed a bug in RefAnyCast causing a crash if the cast is invalid

This commit is contained in:
Günter Obiltschnig
2020-02-13 21:56:59 +01:00
parent 0b59315443
commit 23da8c21c9

View File

@@ -561,14 +561,18 @@ const ValueType& RefAnyCast(const Any & operand)
/// const MyType& tmp = RefAnyCast<MyType>(anAny);
{
ValueType* result = AnyCast<ValueType>(const_cast<Any*>(&operand));
std::string s = "RefAnyCast: Failed to convert between Any types ";
if (operand._pHolder)
if (!result)
{
s.append(1, '(');
s.append(operand._pHolder->type().name());
s.append(" => ");
s.append(typeid(ValueType).name());
s.append(1, ')');
std::string s = "RefAnyCast: Failed to convert between Any types ";
if (operand._pHolder)
{
s.append(1, '(');
s.append(operand._pHolder->type().name());
s.append(" => ");
s.append(typeid(ValueType).name());
s.append(1, ')');
}
throw BadCastException(s);
}
return *result;
}