Further work on better exceptions.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-07-26 17:41:11 +02:00
parent 29eb7c603a
commit 36f1e5beeb
12 changed files with 30 additions and 37 deletions

View File

@@ -25,9 +25,7 @@ namespace CreatureLib::Library {
inline EffectParameterType GetType() const noexcept { return _type; }
bool AsBool() const {
if (_type != EffectParameterType::Bool) {
std::stringstream ss;
ss << "Cast effect parameter to bool, but was " << EffectParameterTypeHelper::ToString(_type);
throw CreatureException(ss.str());
THROW_CREATURE("Cast effect parameter to bool, but was " << EffectParameterTypeHelper::ToString(_type));
}
return std::get<bool>(_value);
}
@@ -36,9 +34,7 @@ namespace CreatureLib::Library {
if (_type == EffectParameterType::Float) {
return static_cast<int64_t>(std::get<float>(_value));
}
std::stringstream ss;
ss << "Cast effect parameter to int, but was " << EffectParameterTypeHelper::ToString(_type);
throw CreatureException(ss.str());
THROW_CREATURE("Cast effect parameter to int, but was " << EffectParameterTypeHelper::ToString(_type));
}
return std::get<int64_t>(_value);
}
@@ -47,17 +43,15 @@ namespace CreatureLib::Library {
if (_type == EffectParameterType::Int) {
return static_cast<float>(std::get<int64_t>(_value));
}
std::stringstream ss;
ss << "Cast effect parameter to float, but was " << EffectParameterTypeHelper::ToString(_type);
throw CreatureException(ss.str());
THROW_CREATURE("Cast effect parameter to float, but was "
<< EffectParameterTypeHelper::ToString(_type));
}
return std::get<float>(_value);
}
const ArbUt::StringView& AsString() const {
if (_type != EffectParameterType::String) {
std::stringstream ss;
ss << "Cast effect parameter to string, but was " << EffectParameterTypeHelper::ToString(_type);
throw CreatureException(ss.str());
THROW_CREATURE("Cast effect parameter to string, but was "
<< EffectParameterTypeHelper::ToString(_type));
}
return std::get<ArbUt::StringView>(_value);
}