Mark Slee | 9f0c651 | 2007-02-28 23:58:26 +0000 | [diff] [blame] | 1 | // Copyright (c) 2006- Facebook |
| 2 | // Distributed under the Thrift Software License |
| 3 | // |
| 4 | // See accompanying file LICENSE or visit the Thrift site at: |
| 5 | // http://developers.facebook.com/thrift/ |
| 6 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 7 | #ifndef _THRIFT_THRIFT_H_ |
| 8 | #define _THRIFT_THRIFT_H_ 1 |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 9 | |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 10 | #include <netinet/in.h> |
| 11 | #include <inttypes.h> |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 12 | #include <string> |
| 13 | #include <map> |
| 14 | #include <list> |
| 15 | #include <set> |
Mark Slee | 4ecbebc | 2006-09-05 00:14:21 +0000 | [diff] [blame] | 16 | #include <vector> |
Marc Slemko | 5b126d6 | 2006-08-11 23:03:42 +0000 | [diff] [blame] | 17 | #include <exception> |
| 18 | |
Aditya Agarwal | d622e96 | 2006-10-11 02:42:49 +0000 | [diff] [blame] | 19 | #include "TLogging.h" |
| 20 | |
Mark Slee | cfc0193 | 2006-09-01 22:18:16 +0000 | [diff] [blame] | 21 | namespace facebook { namespace thrift { |
Marc Slemko | 5b126d6 | 2006-08-11 23:03:42 +0000 | [diff] [blame] | 22 | |
Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 23 | namespace protocol { |
| 24 | class TProtocol; |
| 25 | } |
| 26 | |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 27 | class TException : public std::exception { |
Marc Slemko | 5b126d6 | 2006-08-11 23:03:42 +0000 | [diff] [blame] | 28 | public: |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 29 | TException() {} |
| 30 | |
Mark Slee | 82a6c0f | 2007-04-04 21:08:21 +0000 | [diff] [blame^] | 31 | TException(const std::string& message) : |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 32 | message_(message) {} |
| 33 | |
Martin Kraemer | 8196a61 | 2006-12-09 01:57:58 +0000 | [diff] [blame] | 34 | virtual ~TException() throw() {} |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 35 | |
Martin Kraemer | 92a2eac | 2007-02-05 20:58:41 +0000 | [diff] [blame] | 36 | virtual const char* what() const throw() { |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 37 | if (message_.empty()) { |
| 38 | return "Default TException."; |
| 39 | } else { |
| 40 | return message_.c_str(); |
| 41 | } |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Martin Kraemer | 92a2eac | 2007-02-05 20:58:41 +0000 | [diff] [blame] | 44 | protected: |
Mark Slee | 2abc9df | 2006-12-16 01:06:49 +0000 | [diff] [blame] | 45 | std::string message_; |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 46 | |
Marc Slemko | 5b126d6 | 2006-08-11 23:03:42 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 49 | class TApplicationException : public TException { |
| 50 | public: |
| 51 | |
| 52 | /** |
| 53 | * Error codes for the various types of exceptions. |
| 54 | */ |
| 55 | enum TApplicationExceptionType { |
| 56 | UNKNOWN = 0, |
Mark Slee | f3d3363 | 2007-02-21 01:39:23 +0000 | [diff] [blame] | 57 | UNKNOWN_METHOD = 1, |
| 58 | INVALID_MESSAGE_TYPE = 2, |
| 59 | WRONG_METHOD_NAME = 3, |
| 60 | BAD_SEQUENCE_ID = 4, |
| 61 | MISSING_RESULT = 5, |
Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | TApplicationException() : |
| 65 | TException(), |
| 66 | type_(UNKNOWN) {} |
| 67 | |
| 68 | TApplicationException(TApplicationExceptionType type) : |
| 69 | TException(), |
| 70 | type_(type) {} |
| 71 | |
Mark Slee | 82a6c0f | 2007-04-04 21:08:21 +0000 | [diff] [blame^] | 72 | TApplicationException(const std::string& message) : |
Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 73 | TException(message), |
| 74 | type_(UNKNOWN) {} |
| 75 | |
| 76 | TApplicationException(TApplicationExceptionType type, |
Mark Slee | 82a6c0f | 2007-04-04 21:08:21 +0000 | [diff] [blame^] | 77 | const std::string& message) : |
Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 78 | TException(message), |
| 79 | type_(type) {} |
| 80 | |
| 81 | virtual ~TApplicationException() throw() {} |
| 82 | |
| 83 | /** |
| 84 | * Returns an error code that provides information about the type of error |
| 85 | * that has occurred. |
| 86 | * |
| 87 | * @return Error code |
| 88 | */ |
| 89 | TApplicationExceptionType getType() { |
| 90 | return type_; |
| 91 | } |
| 92 | |
| 93 | virtual const char* what() const throw() { |
| 94 | if (message_.empty()) { |
| 95 | return "Default TApplicationException."; |
| 96 | } else { |
| 97 | return message_.c_str(); |
| 98 | } |
| 99 | } |
| 100 | |
Mark Slee | ba8f8d7 | 2007-04-03 00:34:00 +0000 | [diff] [blame] | 101 | uint32_t read(protocol::TProtocol* iprot); |
| 102 | uint32_t write(protocol::TProtocol* oprot) const; |
Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 103 | |
| 104 | protected: |
| 105 | /** |
| 106 | * Error code |
| 107 | */ |
| 108 | TApplicationExceptionType type_; |
| 109 | |
| 110 | }; |
| 111 | |
| 112 | |
Marc Slemko | 5b126d6 | 2006-08-11 23:03:42 +0000 | [diff] [blame] | 113 | }} // facebook::thrift |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 114 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 115 | #endif // #ifndef _THRIFT_THRIFT_H_ |