Skip to content

Commit

Permalink
Mark all exception type methods as noexcept
Browse files Browse the repository at this point in the history
This is required for the built in exceptions, so let's do the same to
avoid surprises.
  • Loading branch information
CendioOssman committed Nov 26, 2024
1 parent 5c14cd9 commit 0947e09
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
20 changes: 11 additions & 9 deletions common/rdr/Exception.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,22 @@
using namespace rdr;


getaddrinfo_error::getaddrinfo_error(const char* s, int err_)
getaddrinfo_error::getaddrinfo_error(const char* s, int err_) noexcept
: std::runtime_error(rfb::format("%s: %s (%d)", s,
strerror(err_).c_str(), err_)),
err(err_)
{
}

getaddrinfo_error::getaddrinfo_error(const std::string& s, int err_)
getaddrinfo_error::getaddrinfo_error(const std::string& s,
int err_) noexcept
: std::runtime_error(rfb::format("%s: %s (%d)", s.c_str(),
strerror(err_).c_str(), err_)),
err(err_)
{
}

std::string getaddrinfo_error::strerror(int err_) const
std::string getaddrinfo_error::strerror(int err_) const noexcept
{
#ifdef _WIN32
char str[256];
Expand All @@ -71,21 +72,21 @@ std::string getaddrinfo_error::strerror(int err_) const
#endif
}

posix_error::posix_error(const char* what_arg, int err_)
posix_error::posix_error(const char* what_arg, int err_) noexcept
: std::runtime_error(rfb::format("%s: %s (%d)", what_arg,
strerror(err_).c_str(), err_)),
err(err_)
{
}

posix_error::posix_error(const std::string& what_arg, int err_)
posix_error::posix_error(const std::string& what_arg, int err_) noexcept
: std::runtime_error(rfb::format("%s: %s (%d)", what_arg.c_str(),
strerror(err_).c_str(), err_)),
err(err_)
{
}

std::string posix_error::strerror(int err_) const
std::string posix_error::strerror(int err_) const noexcept
{
#ifdef _WIN32
char str[256];
Expand All @@ -100,21 +101,22 @@ std::string posix_error::strerror(int err_) const
}

#ifdef WIN32
win32_error::win32_error(const char* what_arg, unsigned err_)
win32_error::win32_error(const char* what_arg, unsigned err_) noexcept
: std::runtime_error(rfb::format("%s: %s (%d)", what_arg,
strerror(err_).c_str(), err_)),
err(err_)
{
}

win32_error::win32_error(const std::string& what_arg, unsigned err_)
win32_error::win32_error(const std::string& what_arg,
unsigned err_) noexcept
: std::runtime_error(rfb::format("%s: %s (%d)", what_arg.c_str(),
strerror(err_).c_str(), err_)),
err(err_)
{
}

std::string win32_error::strerror(unsigned err_) const
std::string win32_error::strerror(unsigned err_) const noexcept
{
wchar_t wstr[256];
char str[256];
Expand Down
28 changes: 14 additions & 14 deletions common/rdr/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,49 +30,49 @@ namespace rdr {
class posix_error : public std::runtime_error {
public:
int err;
posix_error(const char* what_arg, int err_);
posix_error(const std::string& what_arg, int err_);
posix_error(const char* what_arg, int err_) noexcept;
posix_error(const std::string& what_arg, int err_) noexcept;
private:
std::string strerror(int err_) const;
std::string strerror(int err_) const noexcept;
};

#ifdef WIN32
class win32_error : public std::runtime_error {
public:
unsigned err;
win32_error(const char* what_arg, unsigned err_);
win32_error(const std::string& what_arg, unsigned err_);
win32_error(const char* what_arg, unsigned err_) noexcept;
win32_error(const std::string& what_arg, unsigned err_) noexcept;
private:
std::string strerror(unsigned err_) const;
std::string strerror(unsigned err_) const noexcept;
};
#endif

#ifdef WIN32
class socket_error : public win32_error {
public:
socket_error(const char* what_arg, unsigned err_) : win32_error(what_arg, err_) {}
socket_error(const std::string& what_arg, unsigned err_) : win32_error(what_arg, err_) {}
socket_error(const char* what_arg, unsigned err_) noexcept : win32_error(what_arg, err_) {}
socket_error(const std::string& what_arg, unsigned err_) noexcept : win32_error(what_arg, err_) {}
};
#else
class socket_error : public posix_error {
public:
socket_error(const char* what_arg, unsigned err_) : posix_error(what_arg, err_) {}
socket_error(const std::string& what_arg, unsigned err_) : posix_error(what_arg, err_) {}
socket_error(const char* what_arg, unsigned err_) noexcept : posix_error(what_arg, err_) {}
socket_error(const std::string& what_arg, unsigned err_) noexcept : posix_error(what_arg, err_) {}
};
#endif

class getaddrinfo_error : public std::runtime_error {
public:
int err;
getaddrinfo_error(const char* s, int err_);
getaddrinfo_error(const std::string& s, int err_);
getaddrinfo_error(const char* s, int err_) noexcept;
getaddrinfo_error(const std::string& s, int err_) noexcept;
private:
std::string strerror(int err_) const;
std::string strerror(int err_) const noexcept;
};

class end_of_stream : public std::runtime_error {
public:
end_of_stream() : std::runtime_error("End of stream") {}
end_of_stream() noexcept : std::runtime_error("End of stream") {}
};

}
Expand Down
10 changes: 5 additions & 5 deletions common/rfb/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
namespace rfb {
class protocol_error : public std::runtime_error {
public:
protocol_error(const char* what_arg) : std::runtime_error(what_arg) {}
protocol_error(const std::string& what_arg) : std::runtime_error(what_arg) {}
protocol_error(const char* what_arg) noexcept : std::runtime_error(what_arg) {}
protocol_error(const std::string& what_arg) noexcept : std::runtime_error(what_arg) {}
};

class auth_error : public std::runtime_error {
public:
auth_error(const char* reason) : std::runtime_error(reason) {}
auth_error(std::string& reason) : std::runtime_error(reason) {}
auth_error(const char* reason) noexcept : std::runtime_error(reason) {}
auth_error(std::string& reason) noexcept : std::runtime_error(reason) {}
};

class auth_cancelled : public std::runtime_error {
public:
auth_cancelled()
auth_cancelled() noexcept
: std::runtime_error("Authentication cancelled") {}
};
}
Expand Down

0 comments on commit 0947e09

Please sign in to comment.