diff options
Diffstat (limited to 'cpp/lib/common/Exception.h')
-rw-r--r-- | cpp/lib/common/Exception.h | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/cpp/lib/common/Exception.h b/cpp/lib/common/Exception.h index 61bbc0ab5f..a07e85e7e3 100644 --- a/cpp/lib/common/Exception.h +++ b/cpp/lib/common/Exception.h @@ -21,11 +21,13 @@ * under the License. * */ - #include <exception> #include <string> #include <memory> #include <boost/shared_ptr.hpp> +#include <boost/lexical_cast.hpp> + +#include "amqp_types.h" namespace qpid { @@ -43,6 +45,11 @@ class Exception : public std::exception Exception(const char* str) throw(); Exception(const std::exception&) throw(); + /** Allow any type that has ostream operator<< to act as message */ + template <class T> + Exception(const T& message) + : whatStr(boost::lexical_cast<std::string>(message)) {} + virtual ~Exception() throw(); virtual const char* what() const throw(); @@ -54,16 +61,18 @@ class Exception : public std::exception typedef boost::shared_ptr<Exception> shared_ptr; }; -struct ChannelException : public qpid::Exception { - u_int16_t code; - ChannelException(u_int16_t _code, std::string _text) - : Exception(_text), code(_code) {} +struct ChannelException : public Exception { + framing::ReplyCode code; + template <class T> + ChannelException(framing::ReplyCode code_, const T& message) + : Exception(message), code(code_) {} }; -struct ConnectionException : public qpid::Exception { - u_int16_t code; - ConnectionException(u_int16_t _code, std::string _text) - : Exception(_text), code(_code) {} +struct ConnectionException : public Exception { + framing::ReplyCode code; + template <class T> + ConnectionException(framing::ReplyCode code_, const T& message) + : Exception(message), code(code_) {} }; |