mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-06 00:55:50 +00:00
Revert to lexical_cast<float>, catch out-of-range exceptions
This commit is contained in:
parent
932691d199
commit
e412e1b41c
@ -2,6 +2,8 @@
|
||||
|
||||
#include <components/debug/debuglog.hpp>
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
namespace Fallback
|
||||
{
|
||||
Map::Map(const std::map<std::string,std::string>& fallback):mFallbackMap(fallback)
|
||||
@ -24,9 +26,11 @@ namespace Fallback
|
||||
{
|
||||
try
|
||||
{
|
||||
return std::stof(fallback);
|
||||
// We have to rely on Boost because std::stof from C++11
|
||||
// uses the current locale for separators which we don't want and often silently ignores parsing errors.
|
||||
return boost::lexical_cast<float>(fallback);
|
||||
}
|
||||
catch (const std::invalid_argument&)
|
||||
catch (boost::bad_lexical_cast&)
|
||||
{
|
||||
Log(Debug::Error) << "Error: '" << fall << "' setting value (" << fallback << ") is not a valid number, using 0 as a fallback";
|
||||
}
|
||||
@ -48,6 +52,10 @@ namespace Fallback
|
||||
{
|
||||
Log(Debug::Error) << "Error: '" << fall << "' setting value (" << fallback << ") is not a valid number, using 0 as a fallback";
|
||||
}
|
||||
catch (const std::out_of_range&)
|
||||
{
|
||||
Log(Debug::Error) << "Error: '" << fall << "' setting value (" << fallback << ") is out of range, using 0 as a fallback";
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user