Commit a1e3a3cf authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

let IPAddressFormatException inherit std::runtime_error

Summary: The current approach is not nothrow-copy-constructible, which violates assumptions about exception types.

Differential Revision: D33009493

fbshipit-source-id: 323e0cd8b8a6808dd79c6b8a0f066d46e2293289
parent 891c8860
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <folly/CPortability.h> #include <folly/CPortability.h>
#include <folly/detail/IPAddress.h> #include <folly/detail/IPAddress.h>
#include <folly/lang/Exception.h>
namespace folly { namespace folly {
...@@ -44,38 +45,22 @@ enum class CIDRNetworkError { ...@@ -44,38 +45,22 @@ enum class CIDRNetworkError {
/** /**
* Exception for invalid IP addresses. * Exception for invalid IP addresses.
*/ */
class FOLLY_EXPORT IPAddressFormatException : public std::exception { class FOLLY_EXPORT IPAddressFormatException : public std::runtime_error {
public: public:
explicit IPAddressFormatException(std::string msg) noexcept using std::runtime_error::runtime_error;
: msg_(std::move(msg)) {}
IPAddressFormatException(const IPAddressFormatException&) = default;
IPAddressFormatException(IPAddressFormatException&&) = default;
IPAddressFormatException& operator=(const IPAddressFormatException&) =
default;
IPAddressFormatException& operator=(IPAddressFormatException&&) = default;
~IPAddressFormatException() noexcept override {}
const char* what() const noexcept override { return msg_.c_str(); }
private:
std::string msg_;
}; };
class FOLLY_EXPORT InvalidAddressFamilyException class FOLLY_EXPORT InvalidAddressFamilyException
: public IPAddressFormatException { : public IPAddressFormatException {
public: public:
explicit InvalidAddressFamilyException(std::string msg) noexcept explicit InvalidAddressFamilyException(const char* msg)
: IPAddressFormatException(std::move(msg)) {} : IPAddressFormatException{msg} {}
explicit InvalidAddressFamilyException(const std::string& msg) noexcept
: IPAddressFormatException{msg} {}
explicit InvalidAddressFamilyException(sa_family_t family) noexcept explicit InvalidAddressFamilyException(sa_family_t family) noexcept
: InvalidAddressFamilyException( : InvalidAddressFamilyException(
"Address family " + detail::familyNameStr(family) + "Address family " + detail::familyNameStr(family) +
" is not AF_INET or AF_INET6") {} " is not AF_INET or AF_INET6") {}
InvalidAddressFamilyException(const InvalidAddressFamilyException&) = default;
InvalidAddressFamilyException(InvalidAddressFamilyException&&) = default;
InvalidAddressFamilyException& operator=(
const InvalidAddressFamilyException&) = default;
InvalidAddressFamilyException& operator=(InvalidAddressFamilyException&&) =
default;
}; };
} // namespace folly } // namespace folly
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment