diff --git a/include/support.h b/include/support.h index 646c4117..ce0944af 100644 --- a/include/support.h +++ b/include/support.h @@ -46,6 +46,7 @@ */ template T to_finite(const std::string& input) { + // Defensively set NaN from the get-go T result = std::numeric_limits::quiet_NaN(); size_t bytes_read = 0; try { @@ -53,9 +54,9 @@ T to_finite(const std::string& input) { if (!input.empty() && bytes_read == input.size()) result = static_cast(interim); } - // handle exceptions that stod may throw - catch (std::invalid_argument e) {} - catch (std::out_of_range e) {} + // Capture expected exceptions stod may throw + catch (std::invalid_argument &e) {} + catch (std::out_of_range &e) {} return result; }