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_THRIFT_H_
8 #define _THRIFT_THRIFT_H_ 1
14 #include <netinet/in.h>
15 #ifdef HAVE_INTTYPES_H
27 namespace facebook
{ namespace thrift
{
31 TOutput() : f_(&perrorTimeWrapper
) {}
33 inline void setOutputFunction(void (*function
)(const char *)){
37 inline void operator()(const char *message
){
41 inline static void perrorTimeWrapper(const char* msg
) {
45 ctime_r(&now
, dbgtime
);
47 fprintf(stderr
, "%s ", dbgtime
);
51 void (*f_
)(const char *);
54 extern TOutput GlobalOutput
;
60 class TException
: public std::exception
{
64 TException(const std::string
& message
) :
67 virtual ~TException() throw() {}
69 virtual const char* what() const throw() {
70 if (message_
.empty()) {
71 return "Default TException.";
73 return message_
.c_str();
82 class TApplicationException
: public TException
{
86 * Error codes for the various types of exceptions.
88 enum TApplicationExceptionType
{
91 INVALID_MESSAGE_TYPE
= 2,
92 WRONG_METHOD_NAME
= 3,
97 TApplicationException() :
101 TApplicationException(TApplicationExceptionType type
) :
105 TApplicationException(const std::string
& message
) :
109 TApplicationException(TApplicationExceptionType type
,
110 const std::string
& message
) :
114 virtual ~TApplicationException() throw() {}
117 * Returns an error code that provides information about the type of error
122 TApplicationExceptionType
getType() {
126 virtual const char* what() const throw() {
127 if (message_
.empty()) {
129 case UNKNOWN
: return "TApplicationException: Unknown application exception";
130 case UNKNOWN_METHOD
: return "TApplicationException: Unknown method";
131 case INVALID_MESSAGE_TYPE
: return "TApplicationException: Invalid message type";
132 case WRONG_METHOD_NAME
: return "TApplicationException: Wrong method name";
133 case BAD_SEQUENCE_ID
: return "TApplicationException: Bad sequence identifier";
134 case MISSING_RESULT
: return "TApplicationException: Missing result";
135 default : return "TApplicationException: (Invalid exception type)";
138 return message_
.c_str();
142 uint32_t read(protocol::TProtocol
* iprot
);
143 uint32_t write(protocol::TProtocol
* oprot
) const;
149 TApplicationExceptionType type_
;
154 // Forward declare this structure used by TDenseProtocol
155 namespace reflection
{ namespace local
{
160 }} // facebook::thrift
162 #endif // #ifndef _THRIFT_THRIFT_H_