Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 1 | #ifndef _THRIFT_THRIFT_H_ |
| 2 | #define _THRIFT_THRIFT_H_ 1 |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 3 | |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 4 | #include <netinet/in.h> |
| 5 | #include <inttypes.h> |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 6 | #include <string> |
| 7 | #include <map> |
| 8 | #include <list> |
| 9 | #include <set> |
Mark Slee | 4ecbebc | 2006-09-05 00:14:21 +0000 | [diff] [blame] | 10 | #include <vector> |
Marc Slemko | 5b126d6 | 2006-08-11 23:03:42 +0000 | [diff] [blame] | 11 | #include <exception> |
| 12 | |
Aditya Agarwal | d622e96 | 2006-10-11 02:42:49 +0000 | [diff] [blame] | 13 | #include "TLogging.h" |
| 14 | |
Mark Slee | cfc0193 | 2006-09-01 22:18:16 +0000 | [diff] [blame] | 15 | namespace facebook { namespace thrift { |
Marc Slemko | 5b126d6 | 2006-08-11 23:03:42 +0000 | [diff] [blame] | 16 | |
Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame^] | 17 | namespace protocol { |
| 18 | class TProtocol; |
| 19 | } |
| 20 | |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 21 | class TException : public std::exception { |
Marc Slemko | 5b126d6 | 2006-08-11 23:03:42 +0000 | [diff] [blame] | 22 | public: |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 23 | TException() {} |
| 24 | |
| 25 | TException(const std::string message) : |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 26 | message_(message) {} |
| 27 | |
Martin Kraemer | 8196a61 | 2006-12-09 01:57:58 +0000 | [diff] [blame] | 28 | virtual ~TException() throw() {} |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 29 | |
Martin Kraemer | 92a2eac | 2007-02-05 20:58:41 +0000 | [diff] [blame] | 30 | virtual const char* what() const throw() { |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 31 | if (message_.empty()) { |
| 32 | return "Default TException."; |
| 33 | } else { |
| 34 | return message_.c_str(); |
| 35 | } |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Martin Kraemer | 92a2eac | 2007-02-05 20:58:41 +0000 | [diff] [blame] | 38 | protected: |
Mark Slee | 2abc9df | 2006-12-16 01:06:49 +0000 | [diff] [blame] | 39 | std::string message_; |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 40 | |
Marc Slemko | 5b126d6 | 2006-08-11 23:03:42 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame^] | 43 | class TApplicationException : public TException { |
| 44 | public: |
| 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 | |
| 94 | protected: |
| 95 | /** |
| 96 | * Error code |
| 97 | */ |
| 98 | TApplicationExceptionType type_; |
| 99 | |
| 100 | }; |
| 101 | |
| 102 | |
Marc Slemko | 5b126d6 | 2006-08-11 23:03:42 +0000 | [diff] [blame] | 103 | }} // facebook::thrift |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 104 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 105 | #endif // #ifndef _THRIFT_THRIFT_H_ |