aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2024-09-03 08:02:30 +0200
committerPierre Ossman <ossman@cendio.se>2024-11-06 21:18:52 +0100
commit1093b1eb6f3e561fb80aafba65e3f1505ae80350 (patch)
treefa1e47598653cefc6ba8eb2794065383b92c8cdd /common
parente4c60ef1985164d1207352bbfdf57ae1d7838404 (diff)
downloadtigervnc-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.
Diffstat (limited to 'common')
-rw-r--r--common/rdr/AESInStream.cxx4
-rw-r--r--common/rdr/Exception.cxx34
-rw-r--r--common/rdr/Exception.h37
-rw-r--r--common/rdr/TLSException.cxx3
-rw-r--r--common/rdr/TLSException.h3
-rw-r--r--common/rfb/Exception.h25
-rw-r--r--common/rfb/SSecurityRSAAES.cxx6
-rw-r--r--common/rfb/VNCSConnectionST.cxx2
8 files changed, 74 insertions, 40 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>