diff options
author | Pierre Ossman <ossman@cendio.se> | 2024-09-03 08:02:30 +0200 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2024-11-06 21:18:52 +0100 |
commit | 1093b1eb6f3e561fb80aafba65e3f1505ae80350 (patch) | |
tree | fa1e47598653cefc6ba8eb2794065383b92c8cdd | |
parent | e4c60ef1985164d1207352bbfdf57ae1d7838404 (diff) | |
download | tigervnc-1093b1eb6f3e561fb80aafba65e3f1505ae80350.tar.gz tigervnc-1093b1eb6f3e561fb80aafba65e3f1505ae80350.zip |
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.
-rw-r--r-- | common/rdr/AESInStream.cxx | 4 | ||||
-rw-r--r-- | common/rdr/Exception.cxx | 34 | ||||
-rw-r--r-- | common/rdr/Exception.h | 37 | ||||
-rw-r--r-- | common/rdr/TLSException.cxx | 3 | ||||
-rw-r--r-- | common/rdr/TLSException.h | 3 | ||||
-rw-r--r-- | common/rfb/Exception.h | 25 | ||||
-rw-r--r-- | common/rfb/SSecurityRSAAES.cxx | 6 | ||||
-rw-r--r-- | common/rfb/VNCSConnectionST.cxx | 2 | ||||
-rw-r--r-- | vncviewer/CConn.cxx | 2 | ||||
-rw-r--r-- | vncviewer/ServerDialog.cxx | 4 | ||||
-rw-r--r-- | vncviewer/UserDialog.cxx | 2 | ||||
-rw-r--r-- | vncviewer/parameters.cxx | 4 | ||||
-rw-r--r-- | win/rfb_win32/Clipboard.cxx | 2 | ||||
-rw-r--r-- | win/rfb_win32/DIBSectionBuffer.cxx | 2 | ||||
-rw-r--r-- | win/rfb_win32/WMPoller.cxx | 3 |
15 files changed, 90 insertions, 43 deletions
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 <assert.h> + #include <rdr/AESInStream.h> -#include <rdr/Exception.h> #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 <rdr/Exception.h> +#include <stdexcept> 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 <nettle/base64.h> #include <nettle/asn1.h> +#include <rdr/AESInStream.h> +#include <rdr/AESOutStream.h> +#include <rdr/Exception.h> + #include <rfb/SSecurityRSAAES.h> #include <rfb/SConnection.h> #include <rfb/LogWriter.h> #include <rfb/Exception.h> -#include <rdr/AESInStream.h> -#include <rdr/AESOutStream.h> #if !defined(WIN32) && !defined(__APPLE__) #include <rfb/UnixPasswordValidator.h> #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 <config.h> #endif +#include <rdr/Exception.h> + #include <network/TcpSocket.h> #include <rfb/ComparingUpdateTracker.h> 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 <unistd.h> #endif +#include <rdr/Exception.h> + #include <rfb/CMsgWriter.h> #include <rfb/CSecurity.h> #include <rfb/Exception.h> 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 <FL/Fl_File_Chooser.H> #include <os/os.h> -#include <rfb/Exception.h> + +#include <rdr/Exception.h> + #include <rfb/Hostname.h> #include <rfb/LogWriter.h> #include <rfb/util.h> 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 <FL/Fl_Return_Button.H> #include <FL/Fl_Pixmap.H> +#include <rdr/Exception.h> + #include <rfb/Exception.h> #include <rfb/obfuscate.h> 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 <os/os.h> -#include <rfb/Exception.h> + +#include <rdr/Exception.h> + #include <rfb/LogWriter.h> #include <rfb/SecurityClient.h> #include <rfb/util.h> 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 <config.h> #endif +#include <rdr/Exception.h> + #include <rfb_win32/Clipboard.h> #include <rfb_win32/WMShatter.h> #include <rfb/util.h> 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 <config.h> #endif +#include <rdr/Exception.h> + #include <rfb_win32/DIBSectionBuffer.h> #include <rfb_win32/DeviceContext.h> #include <rfb_win32/BitmapInfo.h> 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 <config.h> #endif +#include <rdr/Exception.h> + #include <rfb_win32/WMPoller.h> -#include <rfb/Exception.h> #include <rfb/LogWriter.h> #include <rfb/Configuration.h> |