Skip to content

Commit be42d77

Browse files
committed
Fall back on std::stoll for std::out_of_range errors
1 parent a4caf38 commit be42d77

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

cpp/arduino/WString.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,15 @@ class String: public string
175175
assign(substr(b, e - b + 1));
176176
}
177177

178-
long toInt(void) const { return std::stol(*this); }
179178
float toFloat(void) const { return std::stof(*this); }
180179
double toDouble(void) const { return std::stod(*this); }
180+
long toInt(void) const {
181+
try {
182+
return std::stol(*this);
183+
} catch (std::out_of_range) {
184+
return std::stoll(*this);
185+
}
186+
}
181187

182188
};
183189

0 commit comments

Comments
 (0)