blob: 469bb7939991d3263a10aa16c10884cd0d8659ff [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,
Mark Sleef3d33632007-02-21 01:39:23 +000051 UNKNOWN_METHOD = 1,
52 INVALID_MESSAGE_TYPE = 2,
53 WRONG_METHOD_NAME = 3,
54 BAD_SEQUENCE_ID = 4,
55 MISSING_RESULT = 5,
Mark Sleef9831082007-02-20 20:59:21 +000056 };
57
58 TApplicationException() :
59 TException(),
60 type_(UNKNOWN) {}
61
62 TApplicationException(TApplicationExceptionType type) :
63 TException(),
64 type_(type) {}
65
66 TApplicationException(const std::string message) :
67 TException(message),
68 type_(UNKNOWN) {}
69
70 TApplicationException(TApplicationExceptionType type,
71 const std::string message) :
72 TException(message),
73 type_(type) {}
74
75 virtual ~TApplicationException() throw() {}
76
77 /**
78 * Returns an error code that provides information about the type of error
79 * that has occurred.
80 *
81 * @return Error code
82 */
83 TApplicationExceptionType getType() {
84 return type_;
85 }
86
87 virtual const char* what() const throw() {
88 if (message_.empty()) {
89 return "Default TApplicationException.";
90 } else {
91 return message_.c_str();
92 }
93 }
94
95 uint32_t TApplicationException::read(facebook::thrift::protocol::TProtocol* iprot);
96 uint32_t TApplicationException::write(facebook::thrift::protocol::TProtocol* oprot) const;
97
98protected:
99 /**
100 * Error code
101 */
102 TApplicationExceptionType type_;
103
104};
105
106
Marc Slemko5b126d62006-08-11 23:03:42 +0000107}} // facebook::thrift
Mark Sleee8540632006-05-30 09:24:40 +0000108
Mark Sleef5f2be42006-09-05 21:05:31 +0000109#endif // #ifndef _THRIFT_THRIFT_H_