From: Pierre Ossman Date: Tue, 3 Sep 2024 06:02:30 +0000 (+0200) Subject: Replace base exception class with standard library X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1093b1eb6f3e561fb80aafba65e3f1505ae80350;p=tigervnc.git Replace base exception class with standard library There is no point to having our own generic exception class. Let's use the one provided by the standard C++ library. --- diff --git a/common/rdr/AESInStream.cxx b/common/rdr/AESInStream.cxx index d6d944a3..3a56ef73 100644 --- a/common/rdr/AESInStream.cxx +++ b/common/rdr/AESInStream.cxx @@ -21,8 +21,8 @@ #endif #include + #include -#include #ifdef HAVE_NETTLE using namespace rdr; @@ -68,7 +68,7 @@ bool AESInStream::fillBuffer() EAX_DIGEST(&eaxCtx256, aes256_encrypt, 16, macComputed); } if (memcmp(mac, macComputed, 16) != 0) - throw Exception("AESInStream: failed to authenticate message"); + throw std::runtime_error("AESInStream: failed to authenticate message"); in->setptr(2 + length + 16); end += length; diff --git a/common/rdr/Exception.cxx b/common/rdr/Exception.cxx index b2c7e7d0..65bd9720 100644 --- a/common/rdr/Exception.cxx +++ b/common/rdr/Exception.cxx @@ -44,7 +44,15 @@ using namespace rdr; GAIException::GAIException(const char* s, int err_) - : Exception(rfb::format("%s: %s (%d)", s, strerror(err_).c_str(), err_)), + : std::runtime_error(rfb::format("%s: %s (%d)", s, + strerror(err_).c_str(), err_)), + err(err_) +{ +} + +GAIException::GAIException(const std::string& s, int err_) + : std::runtime_error(rfb::format("%s: %s (%d)", s.c_str(), + strerror(err_).c_str(), err_)), err(err_) { } @@ -63,8 +71,16 @@ std::string GAIException::strerror(int err_) const #endif } -PosixException::PosixException(const char* s, int err_) - : Exception(rfb::format("%s: %s (%d)", s, strerror(err_).c_str(), err_)), +PosixException::PosixException(const char* what_arg, int err_) + : std::runtime_error(rfb::format("%s: %s (%d)", what_arg, + strerror(err_).c_str(), err_)), + err(err_) +{ +} + +PosixException::PosixException(const std::string& what_arg, int err_) + : std::runtime_error(rfb::format("%s: %s (%d)", what_arg.c_str(), + strerror(err_).c_str(), err_)), err(err_) { } @@ -84,8 +100,16 @@ std::string PosixException::strerror(int err_) const } #ifdef WIN32 -Win32Exception::Win32Exception(const char* s, unsigned err_) - : Exception(rfb::format("%s: %s (%d)", s, strerror(err_).c_str(), err_)), +Win32Exception::Win32Exception(const char* what_arg, unsigned err_) + : std::runtime_error(rfb::format("%s: %s (%d)", what_arg, + strerror(err_).c_str(), err_)), + err(err_) +{ +} + +Win32Exception::Win32Exception(const std::string& what_arg, unsigned err_) + : std::runtime_error(rfb::format("%s: %s (%d)", what_arg.c_str(), + strerror(err_).c_str(), err_)), err(err_) { } diff --git a/common/rdr/Exception.h b/common/rdr/Exception.h index 9ce0462a..3e0ec467 100644 --- a/common/rdr/Exception.h +++ b/common/rdr/Exception.h @@ -27,47 +27,52 @@ namespace rdr { - class Exception : public std::runtime_error { + class PosixException : public std::runtime_error { public: - Exception(const char* what_arg) : std::runtime_error(what_arg) {} - Exception(const std::string& what_arg) : std::runtime_error(what_arg) {} - }; - - struct PosixException : public Exception { int err; - PosixException(const char* s, int err_); + PosixException(const char* what_arg, int err_); + PosixException(const std::string& what_arg, int err_); private: std::string strerror(int err_) const; }; #ifdef WIN32 - struct Win32Exception : public Exception { + class Win32Exception : public std::runtime_error { + public: unsigned err; - Win32Exception(const char* s, unsigned err_); + Win32Exception(const char* what_arg, unsigned err_); + Win32Exception(const std::string& what_arg, unsigned err_); private: std::string strerror(unsigned err_) const; }; #endif #ifdef WIN32 - struct SocketException : public Win32Exception { - SocketException(const char* text, unsigned err_) : Win32Exception(text, err_) {} + class SocketException : public Win32Exception { + public: + SocketException(const char* what_arg, unsigned err_) : Win32Exception(what_arg, err_) {} + SocketException(const std::string& what_arg, unsigned err_) : Win32Exception(what_arg, err_) {} }; #else - struct SocketException : public PosixException { - SocketException(const char* text, int err_) : PosixException(text, err_) {} + class SocketException : public PosixException { + public: + SocketException(const char* what_arg, unsigned err_) : PosixException(what_arg, err_) {} + SocketException(const std::string& what_arg, unsigned err_) : PosixException(what_arg, err_) {} }; #endif - struct GAIException : public Exception { + class GAIException : public std::runtime_error { + public: int err; GAIException(const char* s, int err_); + GAIException(const std::string& s, int err_); private: std::string strerror(int err_) const; }; - struct EndOfStream : public Exception { - EndOfStream() : Exception("End of stream") {} + class EndOfStream : public std::runtime_error { + public: + EndOfStream() : std::runtime_error("End of stream") {} }; } diff --git a/common/rdr/TLSException.cxx b/common/rdr/TLSException.cxx index df2701d3..7061f38b 100644 --- a/common/rdr/TLSException.cxx +++ b/common/rdr/TLSException.cxx @@ -36,7 +36,8 @@ using namespace rdr; #ifdef HAVE_GNUTLS TLSException::TLSException(const char* s, int err_) - : Exception(rfb::format("%s: %s (%d)", s, gnutls_strerror(err_), err_)), + : std::runtime_error(rfb::format("%s: %s (%d)", s, + gnutls_strerror(err_), err_)), err(err_) { } diff --git a/common/rdr/TLSException.h b/common/rdr/TLSException.h index b519bfef..f58b618d 100644 --- a/common/rdr/TLSException.h +++ b/common/rdr/TLSException.h @@ -25,7 +25,8 @@ namespace rdr { - struct TLSException : public Exception { + class TLSException : public std::runtime_error { + public: int err; TLSException(const char* s, int err_); }; diff --git a/common/rfb/Exception.h b/common/rfb/Exception.h index b11609d0..3b81b4a7 100644 --- a/common/rfb/Exception.h +++ b/common/rfb/Exception.h @@ -19,26 +19,25 @@ #ifndef __RFB_EXCEPTION_H__ #define __RFB_EXCEPTION_H__ -#include +#include namespace rfb { - typedef rdr::Exception Exception; - - class ProtocolException : public Exception { + class ProtocolException : public std::runtime_error { public: - ProtocolException(const char* what_arg) : Exception(what_arg) {} - ProtocolException(const std::string& what_arg) : Exception(what_arg) {} + ProtocolException(const char* what_arg) : std::runtime_error(what_arg) {} + ProtocolException(const std::string& what_arg) : std::runtime_error(what_arg) {} }; - struct AuthFailureException : public Exception { - AuthFailureException(const char* reason) - : Exception(reason) {} - AuthFailureException(std::string& reason) - : Exception(reason) {} + class AuthFailureException : public std::runtime_error { + public: + AuthFailureException(const char* reason) : std::runtime_error(reason) {} + AuthFailureException(std::string& reason) : std::runtime_error(reason) {} }; - struct AuthCancelledException : public rfb::Exception { + + class AuthCancelledException : public std::runtime_error { + public: AuthCancelledException() - : Exception("Authentication cancelled") {} + : std::runtime_error("Authentication cancelled") {} }; } #endif diff --git a/common/rfb/SSecurityRSAAES.cxx b/common/rfb/SSecurityRSAAES.cxx index c2fb0f6f..45f5c293 100644 --- a/common/rfb/SSecurityRSAAES.cxx +++ b/common/rfb/SSecurityRSAAES.cxx @@ -37,12 +37,14 @@ #include #include +#include +#include +#include + #include #include #include #include -#include -#include #if !defined(WIN32) && !defined(__APPLE__) #include #endif diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx index 7fa8f626..6f207eb0 100644 --- a/common/rfb/VNCSConnectionST.cxx +++ b/common/rfb/VNCSConnectionST.cxx @@ -22,6 +22,8 @@ #include #endif +#include + #include #include diff --git a/vncviewer/CConn.cxx b/vncviewer/CConn.cxx index 265e2491..90021d95 100644 --- a/vncviewer/CConn.cxx +++ b/vncviewer/CConn.cxx @@ -27,6 +27,8 @@ #include #endif +#include + #include #include #include diff --git a/vncviewer/ServerDialog.cxx b/vncviewer/ServerDialog.cxx index d4ec2006..18909a60 100644 --- a/vncviewer/ServerDialog.cxx +++ b/vncviewer/ServerDialog.cxx @@ -36,7 +36,9 @@ #include #include -#include + +#include + #include #include #include diff --git a/vncviewer/UserDialog.cxx b/vncviewer/UserDialog.cxx index b3840d62..56e6c17f 100644 --- a/vncviewer/UserDialog.cxx +++ b/vncviewer/UserDialog.cxx @@ -36,6 +36,8 @@ #include #include +#include + #include #include diff --git a/vncviewer/parameters.cxx b/vncviewer/parameters.cxx index de728987..b66c7da2 100644 --- a/vncviewer/parameters.cxx +++ b/vncviewer/parameters.cxx @@ -33,7 +33,9 @@ #include "parameters.h" #include -#include + +#include + #include #include #include diff --git a/win/rfb_win32/Clipboard.cxx b/win/rfb_win32/Clipboard.cxx index 5bda26b2..72e8999e 100644 --- a/win/rfb_win32/Clipboard.cxx +++ b/win/rfb_win32/Clipboard.cxx @@ -23,6 +23,8 @@ #include #endif +#include + #include #include #include diff --git a/win/rfb_win32/DIBSectionBuffer.cxx b/win/rfb_win32/DIBSectionBuffer.cxx index 62b917c0..f6447b0d 100644 --- a/win/rfb_win32/DIBSectionBuffer.cxx +++ b/win/rfb_win32/DIBSectionBuffer.cxx @@ -21,6 +21,8 @@ #include #endif +#include + #include #include #include diff --git a/win/rfb_win32/WMPoller.cxx b/win/rfb_win32/WMPoller.cxx index 2c5917e9..db267269 100644 --- a/win/rfb_win32/WMPoller.cxx +++ b/win/rfb_win32/WMPoller.cxx @@ -22,8 +22,9 @@ #include #endif +#include + #include -#include #include #include