Skip to content

Commit 9b29f4e

Browse files
committed
Clean up exception trapping in address utils.
1 parent 550255f commit 9b29f4e

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

src/config/utilities.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ inline bool make_address(asio::address& ip, const std::string& host) NOEXCEPT
5959
ip = boost::asio::ip::make_address(trim_copy(host, { "[", "]" }));
6060
return true;
6161
}
62-
catch (const std::exception&)
62+
catch (...)
6363
{
6464
return false;
6565
}
@@ -160,7 +160,10 @@ inline asio::address to_v4(const boost::asio::ip::address_v6& ip6) THROWS
160160
{
161161
// Required for equivalence with boost 1.86.
162162
if (!ip6.is_v4_mapped())
163-
throw std::exception{};
163+
{
164+
using namespace boost::asio::detail;
165+
throw_exception(boost::asio::ip::bad_address_cast{});
166+
}
164167

165168
const auto bytes = ip6.to_bytes();
166169
return
@@ -187,7 +190,7 @@ asio::address denormalize(const asio::address& ip) NOEXCEPT
187190
{
188191
return { to_v4(ip.to_v6()) };
189192
}
190-
catch (const std::exception&)
193+
catch (...)
191194
{
192195
return ip;
193196
}
@@ -207,7 +210,7 @@ inline std::string to_host(const boost::asio::ip::address_v6& ip6) NOEXCEPT
207210
return ip6.is_v4_mapped() ? to_host(to_v4(ip6)) : ip6.to_string();
208211
BC_POP_WARNING()
209212
}
210-
catch (const std::exception&)
213+
catch (...)
211214
{
212215
return { "::" };
213216
}
@@ -219,7 +222,7 @@ inline std::string to_host(const boost::asio::ip::address_v4& ip4) NOEXCEPT
219222
{
220223
return ip4.to_string();
221224
}
222-
catch (const std::exception&)
225+
catch (...)
223226
{
224227
return { "0.0.0.0" };
225228
}
@@ -235,7 +238,7 @@ std::string to_host(const asio::address& ip) NOEXCEPT
235238
return host.is_v4() ? to_host(host.to_v4()) : to_host(host.to_v6());
236239
BC_POP_WARNING()
237240
}
238-
catch (const std::exception&)
241+
catch (...)
239242
{
240243
return { "0.0.0.0" };
241244
}
@@ -287,7 +290,7 @@ bool is_member(const asio::address& ip, const asio::address& subnet,
287290
if (ip.is_v6() && subnet.is_v6())
288291
return is_member_v6(ip.to_v6(), subnet.to_v6(), cidr);
289292
}
290-
catch (const std::exception&)
293+
catch (...)
291294
{
292295
}
293296

0 commit comments

Comments
 (0)