diff options
| author | Kevin Smith <git@kismith.co.uk> | 2012-05-22 16:05:55 (GMT) |
|---|---|---|
| committer | Kevin Smith <git@kismith.co.uk> | 2012-05-22 16:05:55 (GMT) |
| commit | f813aadb2e45726780ca3ec345bbcd612f4d5177 (patch) | |
| tree | 4934a6042e7c7da1ee0516daa8d41dffe8dcf67b | |
| parent | cd47e717cb2d5789a69582f2661bd110e1e72f37 (diff) | |
| download | swift-contrib-f813aadb2e45726780ca3ec345bbcd612f4d5177.zip swift-contrib-f813aadb2e45726780ca3ec345bbcd612f4d5177.tar.bz2 | |
Allow SluiftExceptions to be output by the EventLoop
| -rw-r--r-- | Sluift/SluiftException.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Sluift/SluiftException.h b/Sluift/SluiftException.h index 28393ab..6964523 100644 --- a/Sluift/SluiftException.h +++ b/Sluift/SluiftException.h @@ -5,25 +5,27 @@ */ #pragma once #include <string> #include <Swiften/Client/ClientError.h> namespace Swift { - class SluiftException { + class SluiftException : public std::exception { public: + virtual ~SluiftException() throw() {} + SluiftException(const std::string& reason) : reason(reason) { } SluiftException(const ClientError& error) { - std::string reason("Disconnected: "); + reason = "Disconnected: "; switch(error.getType()) { case ClientError::UnknownError: reason += "Unknown Error"; break; case ClientError::DomainNameResolveError: reason += "Unable to find server"; break; case ClientError::ConnectionError: reason += "Error connecting to server"; break; case ClientError::ConnectionReadError: reason += "Error while receiving server data"; break; case ClientError::ConnectionWriteError: reason += "Error while sending data to the server"; break; case ClientError::XMLError: reason += "Error parsing server data"; break; case ClientError::AuthenticationFailedError: reason += "Login/password invalid"; break; case ClientError::CompressionFailedError: reason += "Error while compressing stream"; break; @@ -51,13 +53,18 @@ namespace Swift { case ClientError::InvalidCAError: reason += "Invalid Certificate Authority"; break; case ClientError::InvalidServerIdentityError: reason += "Certificate does not match the host identity"; break; } } const std::string& getReason() const { return reason; } + virtual const char* what() const throw() { + return getReason().c_str(); + } + + private: std::string reason; }; } |
Swift