# HG changeset patch # User am@osimis.io # Date 1544023811 -3600 # Node ID 146eaed9b02ce57dd5657eba88920daf06f124cc # Parent 10c610e80b15b6e4cd7abdbbbd9bac14dc00e793 avoid boost::bad_lexical_cast exception in happy path diff -r 10c610e80b15 -r 146eaed9b02c Core/EnumerationDictionary.h --- a/Core/EnumerationDictionary.h Wed Dec 05 15:27:01 2018 +0100 +++ b/Core/EnumerationDictionary.h Wed Dec 05 16:30:11 2018 +0100 @@ -37,6 +37,7 @@ #include "Toolbox.h" #include +#include #include #include @@ -84,12 +85,10 @@ Enumeration Translate(const std::string& str) const { - try + int numericalValue; // at this stage, we don't know if str is an alias or a numerical value + if (boost::conversion::try_lexical_convert(str, numericalValue)) { - return static_cast(boost::lexical_cast(str)); - } - catch (boost::bad_lexical_cast&) - { + return static_cast(numericalValue); } typename StringToEnumeration::const_iterator diff -r 10c610e80b15 -r 146eaed9b02c TODO --- a/TODO Wed Dec 05 15:27:01 2018 +0100 +++ b/TODO Wed Dec 05 16:30:11 2018 +0100 @@ -134,7 +134,8 @@ Release() and Acquire()) * Avoid direct calls to FromDcmtkBridge (make most of its methods private), go through ParsedDicomFile wherever possible - +* avoid boost::bad_lexical_cast exception at least in happy path + by using boost::conversion::try_lexical_convert ================= Platform-specific