2
0
mirror of https://github.com/boostorg/asio.git synced 2026-02-26 14:52:09 +00:00

Check whether exceptions are enabled on the output iostream and throw or not

throw errors accordingly.


[SVN r39504]
This commit is contained in:
Christopher Kohlhoff
2007-09-24 13:21:03 +00:00
parent e5c82d221a
commit 331beee1a6
3 changed files with 44 additions and 10 deletions

View File

@@ -269,7 +269,12 @@ std::basic_ostream<Elem, Traits>& operator<<(
boost::system::error_code ec;
std::string s = addr.to_string(ec);
if (ec)
os.setstate(std::ios_base::failbit);
{
if (os.exceptions() & std::ios::failbit)
boost::asio::detail::throw_error(ec);
else
os.setstate(std::ios_base::failbit);
}
else
for (std::string::iterator i = s.begin(); i != s.end(); ++i)
os << os.widen(*i);

View File

@@ -387,7 +387,12 @@ std::basic_ostream<Elem, Traits>& operator<<(
boost::system::error_code ec;
std::string s = addr.to_string(ec);
if (ec)
os.setstate(std::ios_base::failbit);
{
if (os.exceptions() & std::ios::failbit)
boost::asio::detail::throw_error(ec);
else
os.setstate(std::ios_base::failbit);
}
else
for (std::string::iterator i = s.begin(); i != s.end(); ++i)
os << os.widen(*i);

View File

@@ -342,11 +342,23 @@ std::ostream& operator<<(std::ostream& os,
const basic_endpoint<InternetProtocol>& endpoint)
{
const address& addr = endpoint.address();
if (addr.is_v4())
os << addr.to_string();
boost::system::error_code ec;
std::string a = addr.to_string(ec);
if (ec)
{
if (os.exceptions() & std::ios::failbit)
boost::asio::detail::throw_error(ec);
else
os.setstate(std::ios_base::failbit);
}
else
os << '[' << addr.to_string() << ']';
os << ':' << endpoint.port();
{
if (addr.is_v4())
os << a;
else
os << '[' << a << ']';
os << ':' << endpoint.port();
}
return os;
}
#else // BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
@@ -356,11 +368,23 @@ std::basic_ostream<Elem, Traits>& operator<<(
const basic_endpoint<InternetProtocol>& endpoint)
{
const address& addr = endpoint.address();
if (addr.is_v4())
os << addr.to_string();
boost::system::error_code ec;
std::string a = addr.to_string(ec);
if (ec)
{
if (os.exceptions() & std::ios::failbit)
boost::asio::detail::throw_error(ec);
else
os.setstate(std::ios_base::failbit);
}
else
os << '[' << addr.to_string() << ']';
os << ':' << endpoint.port();
{
if (addr.is_v4())
os << a;
else
os << '[' << a << ']';
os << ':' << endpoint.port();
}
return os;
}
#endif // BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))