diff Core/EnumerationDictionary.h @ 1102:ce6386b37afd

avoid unnecessary exceptions on Orthanc startup
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 07 Aug 2014 10:51:35 +0200
parents 2d0a347e8cfc
children bec1eccf976c
line wrap: on
line diff
--- a/Core/EnumerationDictionary.h	Thu Aug 07 10:21:43 2014 +0200
+++ b/Core/EnumerationDictionary.h	Thu Aug 07 10:51:35 2014 +0200
@@ -34,6 +34,7 @@
 
 #include "OrthancException.h"
 
+#include "Toolbox.h"
 #include <boost/lexical_cast.hpp>
 #include <string>
 #include <map>
@@ -57,22 +58,13 @@
       {
         // Check if these values are free
         if (enumerationToString_.find(value) != enumerationToString_.end() ||
-            stringToEnumeration_.find(str) != stringToEnumeration_.end())
+            stringToEnumeration_.find(str) != stringToEnumeration_.end() ||
+            Toolbox::IsInteger(str) /* Prevent the registration of a number */)
         {
           throw OrthancException(ErrorCode_BadRequest);
         }
 
-        // Prevent the registration of a number
-        try
-        {
-          boost::lexical_cast<int>(str);
-          throw OrthancException(ErrorCode_BadRequest);
-        }
-        catch (boost::bad_lexical_cast)
-        {
-          // OK, the string is not a number
-        }
-
+        // OK, the string is free and is not a number
         enumerationToString_[value] = str;
         stringToEnumeration_[str] = value;
         stringToEnumeration_[boost::lexical_cast<std::string>(static_cast<int>(value))] = value;