blob: d32a21d5e7e4a9e413960486c6c1e65a6fc63ebf [file] [log] [blame]
David Reissac110e42010-03-09 05:20:07 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#ifndef _THRIFT_TAPPLICATIONEXCEPTION_H_
21#define _THRIFT_TAPPLICATIONEXCEPTION_H_ 1
22
Roger Meier49ff8b12012-04-13 09:12:31 +000023#include <thrift/Thrift.h>
David Reissac110e42010-03-09 05:20:07 +000024
25
26namespace apache { namespace thrift {
27
28namespace protocol {
29 class TProtocol;
30}
31
32class TApplicationException : public TException {
33 public:
34
35 /**
36 * Error codes for the various types of exceptions.
37 */
38 enum TApplicationExceptionType {
39 UNKNOWN = 0,
40 UNKNOWN_METHOD = 1,
41 INVALID_MESSAGE_TYPE = 2,
42 WRONG_METHOD_NAME = 3,
43 BAD_SEQUENCE_ID = 4,
Roger Meier345ecc72011-08-03 09:49:27 +000044 MISSING_RESULT = 5,
45 INTERNAL_ERROR = 6,
Roger Meier01931492012-12-22 21:31:03 +010046 PROTOCOL_ERROR = 7,
47 INVALID_TRANSFORM = 8,
48 INVALID_PROTOCOL = 9,
49 UNSUPPORTED_CLIENT_TYPE = 10
David Reissac110e42010-03-09 05:20:07 +000050 };
51
52 TApplicationException() :
53 TException(),
54 type_(UNKNOWN) {}
55
56 TApplicationException(TApplicationExceptionType type) :
57 TException(),
58 type_(type) {}
59
60 TApplicationException(const std::string& message) :
61 TException(message),
62 type_(UNKNOWN) {}
63
64 TApplicationException(TApplicationExceptionType type,
65 const std::string& message) :
66 TException(message),
67 type_(type) {}
68
69 virtual ~TApplicationException() throw() {}
70
71 /**
72 * Returns an error code that provides information about the type of error
73 * that has occurred.
74 *
75 * @return Error code
76 */
77 TApplicationExceptionType getType() {
78 return type_;
79 }
80
81 virtual const char* what() const throw() {
82 if (message_.empty()) {
83 switch (type_) {
Roger Meier01931492012-12-22 21:31:03 +010084 case UNKNOWN : return "TApplicationException: Unknown application exception";
85 case UNKNOWN_METHOD : return "TApplicationException: Unknown method";
86 case INVALID_MESSAGE_TYPE : return "TApplicationException: Invalid message type";
87 case WRONG_METHOD_NAME : return "TApplicationException: Wrong method name";
88 case BAD_SEQUENCE_ID : return "TApplicationException: Bad sequence identifier";
89 case MISSING_RESULT : return "TApplicationException: Missing result";
90 case INTERNAL_ERROR : return "TApplicationException: Internal error";
91 case PROTOCOL_ERROR : return "TApplicationException: Protocol error";
92 case INVALID_TRANSFORM : return "TApplicationException: Invalid transform";
93 case INVALID_PROTOCOL : return "TApplicationException: Invalid protocol";
94 case UNSUPPORTED_CLIENT_TYPE : return "TApplicationException: Unsupported client type";
95 default : return "TApplicationException: (Invalid exception type)";
David Reissac110e42010-03-09 05:20:07 +000096 };
97 } else {
98 return message_.c_str();
99 }
100 }
101
102 uint32_t read(protocol::TProtocol* iprot);
103 uint32_t write(protocol::TProtocol* oprot) const;
104
105 protected:
106 /**
107 * Error code
108 */
109 TApplicationExceptionType type_;
110
111};
112
113}} // apache::thrift
114
115#endif // #ifndef _THRIFT_TAPPLICATIONEXCEPTION_H_