mirror of https://github.com/stella-emu/stella.git
catch exception in BSPF::stoi (fixes #958)
This commit is contained in:
parent
7676e9b4c8
commit
93ea39d615
|
@ -197,10 +197,13 @@ namespace BSPF
|
|||
template<int BASE = 10>
|
||||
inline int stoi(string_view s, const int defaultValue = 0)
|
||||
{
|
||||
int i{};
|
||||
s = s.substr(s.find_first_not_of(" "));
|
||||
auto result = std::from_chars(s.data(), s.data() + s.size(), i, BASE);
|
||||
return result.ec == std::errc() ? i : defaultValue;
|
||||
try {
|
||||
int i{};
|
||||
s = s.substr(s.find_first_not_of(" "));
|
||||
auto result = std::from_chars(s.data(), s.data() + s.size(), i, BASE);
|
||||
return result.ec == std::errc() ? i : defaultValue;
|
||||
}
|
||||
catch(...) { return defaultValue; }
|
||||
}
|
||||
|
||||
// Compare two strings (case insensitive)
|
||||
|
|
Loading…
Reference in New Issue