Skip to content

TauWPThreshold uses exceptions in string parsing #39627

Open
@makortel

Description

@makortel

The deep_tau::TauWPThreshold constructor uses exceptions string parsing

try {
size_t pos = 0;
value_ = std::stod(cut_str, &pos);
simple_value = (pos == cut_str.size());
} catch (std::invalid_argument&) {
} catch (std::out_of_range&) {
}

I encountered this exception being thrown many times (don't know how many because I gave up) when trying to catch a different exception, so the parse error does not seem to be as exceptional that exceptions would be justified (see https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideEdmExceptionUse#Exception_Handling,
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Re-throw
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Re-errors)

I'd suggest to parse the string in a way that does not use exceptions to signal an invalid value. E,g, std::from_chars() looks like a good candidate, but GCC (or libstdc++) implements it for floating point numbers only in version 11 (to which we'll hopefully switch to soon). An alternative could be std::strtod (from C) or std::istringstream (expensive).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions