1 // Copyright (c) 2006- Facebook
2 // Distributed under the Thrift Software License
4 // See accompanying file LICENSE or visit the Thrift site at:
5 // http://developers.facebook.com/thrift/
7 #ifndef _THRIFT_PROTOCOL_TPROTOCOLEXCEPTION_H_
8 #define _THRIFT_PROTOCOL_TPROTOCOLEXCEPTION_H_ 1
10 #include <boost/lexical_cast.hpp>
13 namespace facebook
{ namespace thrift
{ namespace protocol
{
16 * Class to encapsulate all the possible types of protocol errors that may
17 * occur in various protocol systems. This provides a sort of generic
18 * wrapper around the shitty UNIX E_ error codes that lets a common code
19 * base of error handling to be used for various types of protocols, i.e.
22 * @author Mark Slee <mcslee@facebook.com>
24 class TProtocolException
: public facebook::thrift::TException
{
28 * Error codes for the various types of exceptions.
30 enum TProtocolExceptionType
{
39 TProtocolException() :
40 facebook::thrift::TException(),
43 TProtocolException(TProtocolExceptionType type
) :
44 facebook::thrift::TException(),
47 TProtocolException(const std::string
& message
) :
48 facebook::thrift::TException(message
),
51 TProtocolException(TProtocolExceptionType type
, const std::string
& message
) :
52 facebook::thrift::TException(message
),
55 virtual ~TProtocolException() throw() {}
58 * Returns an error code that provides information about the type of error
63 TProtocolExceptionType
getType() {
67 virtual const char* what() const throw() {
68 if (message_
.empty()) {
70 case UNKNOWN
: return "TProtocolException: Unknown protocol exception";
71 case INVALID_DATA
: return "TProtocolException: Invalid data";
72 case NEGATIVE_SIZE
: return "TProtocolException: Negative size";
73 case SIZE_LIMIT
: return "TProtocolException: Exceeded size limit";
74 case BAD_VERSION
: return "TProtocolException: Invalid version";
75 case NOT_IMPLEMENTED
: return "TProtocolException: Not implemented";
76 default : return "TProtocolException: (Invalid exception type)";
79 return message_
.c_str();
87 TProtocolExceptionType type_
;
91 }}} // facebook::thrift::protocol
93 #endif // #ifndef _THRIFT_PROTOCOL_TPROTOCOLEXCEPTION_H_