blob: 61edf5b82769023b1bafc8a176fd14a7b152479a [file] [log] [blame]
Mark Sleef5f2be42006-09-05 21:05:31 +00001#ifndef _THRIFT_THRIFT_H_
2#define _THRIFT_THRIFT_H_ 1
Mark Sleee8540632006-05-30 09:24:40 +00003
Mark Slee8d7e1f62006-06-07 06:48:56 +00004#include <netinet/in.h>
5#include <inttypes.h>
Mark Sleee8540632006-05-30 09:24:40 +00006#include <string>
7#include <map>
8#include <list>
9#include <set>
Mark Slee4ecbebc2006-09-05 00:14:21 +000010#include <vector>
Marc Slemko5b126d62006-08-11 23:03:42 +000011#include <exception>
12
Aditya Agarwald622e962006-10-11 02:42:49 +000013#include "TLogging.h"
14
Mark Sleecfc01932006-09-01 22:18:16 +000015namespace facebook { namespace thrift {
Marc Slemko5b126d62006-08-11 23:03:42 +000016
Mark Sleef9831082007-02-20 20:59:21 +000017namespace protocol {
18 class TProtocol;
19}
20
Mark Sleeb9ff32a2006-11-16 01:00:24 +000021class TException : public std::exception {
Marc Slemko5b126d62006-08-11 23:03:42 +000022public:
Mark Sleeb9ff32a2006-11-16 01:00:24 +000023 TException() {}
24
25 TException(const std::string message) :
Mark Slee2f6404d2006-10-10 01:37:40 +000026 message_(message) {}
27
Martin Kraemer8196a612006-12-09 01:57:58 +000028 virtual ~TException() throw() {}
Mark Slee2f6404d2006-10-10 01:37:40 +000029
Martin Kraemer92a2eac2007-02-05 20:58:41 +000030 virtual const char* what() const throw() {
Mark Sleeb9ff32a2006-11-16 01:00:24 +000031 if (message_.empty()) {
32 return "Default TException.";
33 } else {
34 return message_.c_str();
35 }
Mark Slee2f6404d2006-10-10 01:37:40 +000036 }
37
Martin Kraemer92a2eac2007-02-05 20:58:41 +000038protected:
Mark Slee2abc9df2006-12-16 01:06:49 +000039 std::string message_;
Mark Slee2f6404d2006-10-10 01:37:40 +000040
Marc Slemko5b126d62006-08-11 23:03:42 +000041};
42
Mark Sleef9831082007-02-20 20:59:21 +000043class TApplicationException : public TException {
44public:
45
46 /**
47 * Error codes for the various types of exceptions.
48 */
49 enum TApplicationExceptionType {
50 UNKNOWN = 0,
51 INVALID_METHOD = 1,
52 };
53
54 TApplicationException() :
55 TException(),
56 type_(UNKNOWN) {}
57
58 TApplicationException(TApplicationExceptionType type) :
59 TException(),
60 type_(type) {}
61
62 TApplicationException(const std::string message) :
63 TException(message),
64 type_(UNKNOWN) {}
65
66 TApplicationException(TApplicationExceptionType type,
67 const std::string message) :
68 TException(message),
69 type_(type) {}
70
71 virtual ~TApplicationException() throw() {}
72
73 /**
74 * Returns an error code that provides information about the type of error
75 * that has occurred.
76 *
77 * @return Error code
78 */
79 TApplicationExceptionType getType() {
80 return type_;
81 }
82
83 virtual const char* what() const throw() {
84 if (message_.empty()) {
85 return "Default TApplicationException.";
86 } else {
87 return message_.c_str();
88 }
89 }
90
91 uint32_t TApplicationException::read(facebook::thrift::protocol::TProtocol* iprot);
92 uint32_t TApplicationException::write(facebook::thrift::protocol::TProtocol* oprot) const;
93
94protected:
95 /**
96 * Error code
97 */
98 TApplicationExceptionType type_;
99
100};
101
102
Marc Slemko5b126d62006-08-11 23:03:42 +0000103}} // facebook::thrift
Mark Sleee8540632006-05-30 09:24:40 +0000104
Mark Sleef5f2be42006-09-05 21:05:31 +0000105#endif // #ifndef _THRIFT_THRIFT_H_