From 1d9b2f9984fefbc050c8e3295397ffd280e41788 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 2 Sep 2024 22:58:35 +0200 Subject: Use standard exception classes Use the more specific already included exception classes for common errors to keep things more understandable. --- common/network/Socket.cxx | 2 ++ common/network/TcpSocket.cxx | 18 +++++++++++------- common/network/UnixSocket.cxx | 3 +++ 3 files changed, 16 insertions(+), 7 deletions(-) (limited to 'common/network') diff --git a/common/network/Socket.cxx b/common/network/Socket.cxx index 8bb96763..03844acd 100644 --- a/common/network/Socket.cxx +++ b/common/network/Socket.cxx @@ -39,6 +39,8 @@ #include #include +#include + #include using namespace network; diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx index 38cb6eb3..455df749 100644 --- a/common/network/TcpSocket.cxx +++ b/common/network/TcpSocket.cxx @@ -38,7 +38,10 @@ #include #include +#include + #include + #include #include #include @@ -200,7 +203,7 @@ TcpSocket::TcpSocket(const char *host, int port) if (sock == -1) { if (err == 0) - throw Exception("No useful address for host"); + throw std::runtime_error("No useful address for host"); else throw SocketException("unable to connect to socket", err); } @@ -607,7 +610,7 @@ TcpFilter::Pattern TcpFilter::parsePattern(const char* p) { parts = rfb::split(&p[1], '/'); if (parts.size() > 2) - throw Exception("invalid filter specified"); + throw std::invalid_argument("invalid filter specified"); if (parts[0].empty()) { // Match any address @@ -641,8 +644,8 @@ TcpFilter::Pattern TcpFilter::parsePattern(const char* p) { if (parts.size() > 1) { if (family == AF_INET && (parts[1].find('.') != std::string::npos)) { - throw Exception("mask no longer supported for filter, " - "use prefix instead"); + throw std::invalid_argument("mask no longer supported for " + "filter, use prefix instead"); } pattern.prefixlen = (unsigned int) atoi(parts[1].c_str()); @@ -655,7 +658,7 @@ TcpFilter::Pattern TcpFilter::parsePattern(const char* p) { pattern.prefixlen = 128; break; default: - throw Exception("unknown address family"); + throw std::runtime_error("unknown address family"); } } } @@ -663,8 +666,9 @@ TcpFilter::Pattern TcpFilter::parsePattern(const char* p) { family = pattern.address.u.sa.sa_family; if (pattern.prefixlen > (family == AF_INET ? 32: 128)) - throw Exception(rfb::format("invalid prefix length for filter address: %u", - pattern.prefixlen)); + throw std::invalid_argument(rfb::format("invalid prefix length for " + "filter address: %u", + pattern.prefixlen)); // Compute mask from address and prefix length memset (&pattern.mask, 0, sizeof (pattern.mask)); diff --git a/common/network/UnixSocket.cxx b/common/network/UnixSocket.cxx index 3a422b6c..4b82b4b7 100644 --- a/common/network/UnixSocket.cxx +++ b/common/network/UnixSocket.cxx @@ -29,7 +29,10 @@ #include #include +#include + #include + #include using namespace network; -- cgit v1.2.3