diff options
author | Tobias Markmann <tm@ayena.de> | 2016-09-30 17:59:31 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2016-09-30 17:59:31 (GMT) |
commit | 1e8670bd64efcc51cb435880a4e11337c56b1a0f (patch) | |
tree | 6dcca792c7d34833dfe3d230e0ce0e7847aec4e6 /Swiften/Network | |
parent | cb41a41239bd75db8a3ed6d5b3013104e393d0ad (diff) | |
download | swift-1e8670bd64efcc51cb435880a4e11337c56b1a0f.zip swift-1e8670bd64efcc51cb435880a4e11337c56b1a0f.tar.bz2 |
Add missing error check in HostAddress::toString
In the process converted try/catch use to Boost's error code
for more explicit error checking and added log output.
Test-Information:
Swift builds with test=all on macOS 10.12 and all tests pass.
Change-Id: I6e465354dbb38c7178b0406b9a544ebd3be62ddd
Diffstat (limited to 'Swiften/Network')
-rw-r--r-- | Swiften/Network/HostAddress.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/Swiften/Network/HostAddress.cpp b/Swiften/Network/HostAddress.cpp index 64a4ff6..7738079 100644 --- a/Swiften/Network/HostAddress.cpp +++ b/Swiften/Network/HostAddress.cpp @@ -7,7 +7,6 @@ #include <Swiften/Network/HostAddress.h> #include <cassert> -#include <stdexcept> #include <string> #include <boost/array.hpp> @@ -15,6 +14,7 @@ #include <boost/numeric/conversion/cast.hpp> #include <Swiften/Base/foreach.h> +#include <Swiften/Base/Log.h> static boost::asio::ip::address localhost4 = boost::asio::ip::address(boost::asio::ip::address_v4::loopback()); static boost::asio::ip::address localhost6 = boost::asio::ip::address(boost::asio::ip::address_v6::loopback()); @@ -25,10 +25,10 @@ HostAddress::HostAddress() { } HostAddress::HostAddress(const std::string& address) { - try { - address_ = boost::asio::ip::address::from_string(address); - } - catch (const std::exception&) { + boost::system::error_code errorCode; + address_ = boost::asio::ip::address::from_string(address, errorCode); + if (errorCode) { + SWIFT_LOG(warning) << "error: " << errorCode.message() << std::endl; } } @@ -54,7 +54,15 @@ HostAddress::HostAddress(const boost::asio::ip::address& address) : address_(add } std::string HostAddress::toString() const { - return address_.to_string(); + std::string addressString; + boost::system::error_code errorCode; + + addressString = address_.to_string(errorCode); + if (errorCode) { + SWIFT_LOG(debug) << "error: " << errorCode.message() << std::endl; + } + + return addressString; } bool HostAddress::isValid() const { |