Wrap a few boost asio exceptions in fc exceptions

This commit is contained in:
Eric Frias 2014-09-16 09:33:51 -04:00
parent d44d72b0d9
commit 7966587021

View file

@ -10,8 +10,13 @@ namespace fc { namespace ip {
address::address( uint32_t ip ) address::address( uint32_t ip )
:_ip(ip){} :_ip(ip){}
address::address( const fc::string& s ) { address::address( const fc::string& s )
_ip = boost::asio::ip::address_v4::from_string(s.c_str()).to_ulong(); {
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 ) { bool operator==( const address& a, const address& b ) {
@ -21,13 +26,23 @@ namespace fc { namespace ip {
return uint32_t(a) != uint32_t(b); return uint32_t(a) != uint32_t(b);
} }
address& address::operator=( const fc::string& s ) { address& address::operator=( const fc::string& s )
_ip = boost::asio::ip::address_v4::from_string(s.c_str()).to_ulong(); {
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; return *this;
} }
address::operator fc::string()const { address::operator fc::string()const
return boost::asio::ip::address_v4(_ip).to_string().c_str(); {
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 { address::operator uint32_t()const {
return _ip; return _ip;
@ -69,8 +84,13 @@ namespace fc { namespace ip {
FC_RETHROW_EXCEPTIONS(warn, "error converting string to IP endpoint") FC_RETHROW_EXCEPTIONS(warn, "error converting string to IP endpoint")
} }
endpoint::operator string()const { endpoint::operator string()const
return string(_ip) + ':' + fc::string(boost::lexical_cast<std::string>(_port).c_str()); {
try
{
return string(_ip) + ':' + fc::string(boost::lexical_cast<std::string>(_port).c_str());
}
FC_RETHROW_EXCEPTIONS(warn, "error converting IP endpoint to string")
} }
/** /**