From 7966587021dae7b2441816a06418077849671a60 Mon Sep 17 00:00:00 2001 From: Eric Frias Date: Tue, 16 Sep 2014 09:33:51 -0400 Subject: [PATCH] Wrap a few boost asio exceptions in fc exceptions --- src/network/ip.cpp | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/network/ip.cpp b/src/network/ip.cpp index fd458ba..1961659 100644 --- a/src/network/ip.cpp +++ b/src/network/ip.cpp @@ -10,8 +10,13 @@ namespace fc { namespace ip { address::address( uint32_t ip ) :_ip(ip){} - address::address( const fc::string& s ) { - _ip = boost::asio::ip::address_v4::from_string(s.c_str()).to_ulong(); + address::address( const fc::string& s ) + { + try + { + _ip = boost::asio::ip::address_v4::from_string(s.c_str()).to_ulong(); + } + FC_RETHROW_EXCEPTIONS(error, "Error parsing IP address ${address}", ("address", s)) } bool operator==( const address& a, const address& b ) { @@ -21,13 +26,23 @@ namespace fc { namespace ip { return uint32_t(a) != uint32_t(b); } - address& address::operator=( const fc::string& s ) { - _ip = boost::asio::ip::address_v4::from_string(s.c_str()).to_ulong(); + address& address::operator=( const fc::string& s ) + { + try + { + _ip = boost::asio::ip::address_v4::from_string(s.c_str()).to_ulong(); + } + FC_RETHROW_EXCEPTIONS(error, "Error parsing IP address ${address}", ("address", s)) return *this; } - address::operator fc::string()const { - return boost::asio::ip::address_v4(_ip).to_string().c_str(); + address::operator fc::string()const + { + try + { + return boost::asio::ip::address_v4(_ip).to_string().c_str(); + } + FC_RETHROW_EXCEPTIONS(error, "Error parsing IP address to string") } address::operator uint32_t()const { return _ip; @@ -69,8 +84,13 @@ namespace fc { namespace ip { FC_RETHROW_EXCEPTIONS(warn, "error converting string to IP endpoint") } - endpoint::operator string()const { - return string(_ip) + ':' + fc::string(boost::lexical_cast(_port).c_str()); + endpoint::operator string()const + { + try + { + return string(_ip) + ':' + fc::string(boost::lexical_cast(_port).c_str()); + } + FC_RETHROW_EXCEPTIONS(warn, "error converting IP endpoint to string") } /**