From: Mikko Rasa Date: Fri, 9 Dec 2022 18:31:16 +0000 (+0200) Subject: Adjust exception classes and messages X-Git-Url: http://git.tdb.fi/?p=libs%2Fnet.git;a=commitdiff_plain;h=5afa6e0e07b20ef58d262d69d96971df9a4be71f Adjust exception classes and messages --- diff --git a/source/http/client.cpp b/source/http/client.cpp index e090576..705f4cb 100644 --- a/source/http/client.cpp +++ b/source/http/client.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -53,7 +54,7 @@ void Client::use_resolver(Net::Resolver *r) void Client::start_request(const Request &r) { if(request) - throw client_busy(); + throw invalid_state("already processing a request"); delete sock; sock = 0; diff --git a/source/http/client.h b/source/http/client.h index d617ffe..e0b9b64 100644 --- a/source/http/client.h +++ b/source/http/client.h @@ -10,12 +10,6 @@ namespace Msp { namespace Http { -class client_busy: public std::logic_error -{ -public: - client_busy(): std::logic_error(std::string()) { } -}; - class Request; class Response; diff --git a/source/net/communicator.h b/source/net/communicator.h index 62521ee..575ec84 100644 --- a/source/net/communicator.h +++ b/source/net/communicator.h @@ -1,6 +1,7 @@ #ifndef MSP_NET_COMMUNICATOR_H_ #define MSP_NET_COMMUNICATOR_H_ +#include #include #include "protocol.h" @@ -9,10 +10,10 @@ namespace Net { class StreamSocket; -class sequence_error: public std::logic_error +class sequence_error: public invalid_state { public: - sequence_error(const std::string &w): std::logic_error(w) { } + sequence_error(const std::string &w): invalid_state(w) { } }; class incompatible_protocol: public std::runtime_error diff --git a/source/net/serversocket.cpp b/source/net/serversocket.cpp index 051ac50..01fa445 100644 --- a/source/net/serversocket.cpp +++ b/source/net/serversocket.cpp @@ -1,3 +1,4 @@ +#include #include "serversocket.h" using namespace std; @@ -11,12 +12,12 @@ ServerSocket::ServerSocket(Family af, int type, int proto): size_t ServerSocket::do_write(const char *, size_t) { - throw logic_error("can't write to ServerSocket"); + throw unsupported("ServerSocket::write"); } size_t ServerSocket::do_read(char *, size_t) { - throw logic_error("can't read from ServerSocket"); + throw unsupported("ServerSocket::read"); } } // namespace Net diff --git a/source/net/socket.cpp b/source/net/socket.cpp index 85cc987..9fd468e 100644 --- a/source/net/socket.cpp +++ b/source/net/socket.cpp @@ -60,7 +60,7 @@ void Socket::set_inherit(bool i) const IO::Handle &Socket::get_handle(IO::Mode) { // TODO could this be implemented somehow? - throw logic_error("Socket::get_handle"); + throw unsupported("Socket::get_handle"); } const IO::Handle &Socket::get_event_handle() diff --git a/source/net/socket.h b/source/net/socket.h index a3823ee..2e736e9 100644 --- a/source/net/socket.h +++ b/source/net/socket.h @@ -1,6 +1,7 @@ #ifndef MSP_NET_SOCKET_H_ #define MSP_NET_SOCKET_H_ +#include #include #include #include "constants.h" @@ -9,10 +10,10 @@ namespace Msp { namespace Net { -class bad_socket_state: public std::logic_error +class bad_socket_state: public invalid_state { public: - bad_socket_state(const std::string &w): std::logic_error(w) { } + bad_socket_state(const std::string &w): invalid_state(w) { } }; diff --git a/source/net/unix/unix.cpp b/source/net/unix/unix.cpp index 6bb3436..0e88c2c 100644 --- a/source/net/unix/unix.cpp +++ b/source/net/unix/unix.cpp @@ -25,7 +25,7 @@ UnixAddr::UnixAddr(const string &p, bool a): abstract(a) { if(sizeof(sa_family_t)+path.size()+1>sizeof(sockaddr_storage)) - throw invalid_argument("UnixAddr"); + throw invalid_argument("UnixAddr::UnixAddr"); } SockAddr::SysAddr UnixAddr::to_sys() const diff --git a/source/net/windows/unix.cpp b/source/net/windows/unix.cpp index 2aa8857..052710e 100644 --- a/source/net/windows/unix.cpp +++ b/source/net/windows/unix.cpp @@ -1,4 +1,4 @@ -#include +#include #include "platform_api.h" #include "sockaddr_private.h" #include "unix.h" @@ -11,7 +11,7 @@ namespace Net { UnixAddr::UnixAddr(const SysAddr &): abstract(false) { - throw logic_error("AF_UNIX not supported"); + throw unsupported("AF_UNIX"); } UnixAddr::UnixAddr(const string &p, bool a): @@ -22,7 +22,7 @@ UnixAddr::UnixAddr(const string &p, bool a): SockAddr::SysAddr UnixAddr::to_sys() const { - throw logic_error("AF_UNIX not supported"); + throw unsupported("AF_UNIX"); } } // namespace Net