From 594ef43f76a4c1e471e2d160d54f5cb4d88777db Mon Sep 17 00:00:00 2001 From: drltc Date: Mon, 15 Dec 2014 08:18:58 -0500 Subject: [PATCH] Wrap boost exceptions thrown by to_int64, to_uint64, to_double --- src/string.cpp | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/src/string.cpp b/src/string.cpp index 6499494..3850912 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -89,19 +89,43 @@ namespace fc { int64_t to_int64( const fc::string& i ) - { try { - return boost::lexical_cast(i.c_str()); - } FC_RETHROW_EXCEPTIONS( warn, "${i} => int64_t", ("i",i) ) } + { + try + { + return boost::lexical_cast(i.c_str()); + } + catch( const boost::bad_lexical_cast& e ) + { + FC_THROW_EXCEPTION( parse_error_exception, "Couldn't parse int64_t" ); + } + FC_RETHROW_EXCEPTIONS( warn, "${i} => int64_t", ("i",i) ) + } uint64_t to_uint64( const fc::string& i ) - { try { - return boost::lexical_cast(i.c_str()); - } FC_RETHROW_EXCEPTIONS( warn, "${i} => uint64_t", ("i",i) ) } + { + try + { + return boost::lexical_cast(i.c_str()); + } + catch( const boost::bad_lexical_cast& e ) + { + FC_THROW_EXCEPTION( parse_error_exception, "Couldn't parse uint64_t" ); + } + FC_RETHROW_EXCEPTIONS( warn, "${i} => uint64_t", ("i",i) ) + } double to_double( const fc::string& i) - { try { - return boost::lexical_cast(i.c_str()); - } FC_RETHROW_EXCEPTIONS( warn, "${i} => double", ("i",i) ) } + { + try + { + return boost::lexical_cast(i.c_str()); + } + catch( const boost::bad_lexical_cast& e ) + { + FC_THROW_EXCEPTION( parse_error_exception, "Couldn't parse double" ); + } + FC_RETHROW_EXCEPTIONS( warn, "${i} => double", ("i",i) ) + } fc::string to_string( double d) {