blob: 61e68644ecd4b6c3782b48ac10de965daf0314e7 [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
23#include <Thrift.h>
24
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,
46 PROTOCOL_ERROR = 7
David Reissac110e42010-03-09 05:20:07 +000047 };
48
49 TApplicationException() :
50 TException(),
51 type_(UNKNOWN) {}
52
53 TApplicationException(TApplicationExceptionType type) :
54 TException(),
55 type_(type) {}
56
57 TApplicationException(const std::string& message) :
58 TException(message),
59 type_(UNKNOWN) {}
60
61 TApplicationException(TApplicationExceptionType type,
62 const std::string& message) :
63 TException(message),
64 type_(type) {}
65
66 virtual ~TApplicationException() throw() {}
67
68 /**
69 * Returns an error code that provides information about the type of error
70 * that has occurred.
71 *
72 * @return Error code
73 */
74 TApplicationExceptionType getType() {
75 return type_;
76 }
77
78 virtual const char* what() const throw() {
79 if (message_.empty()) {
80 switch (type_) {
81 case UNKNOWN : return "TApplicationException: Unknown application exception";
82 case UNKNOWN_METHOD : return "TApplicationException: Unknown method";
83 case INVALID_MESSAGE_TYPE : return "TApplicationException: Invalid message type";
84 case WRONG_METHOD_NAME : return "TApplicationException: Wrong method name";
85 case BAD_SEQUENCE_ID : return "TApplicationException: Bad sequence identifier";
86 case MISSING_RESULT : return "TApplicationException: Missing result";
87 default : return "TApplicationException: (Invalid exception type)";
88 };
89 } else {
90 return message_.c_str();
91 }
92 }
93
94 uint32_t read(protocol::TProtocol* iprot);
95 uint32_t write(protocol::TProtocol* oprot) const;
96
97 protected:
98 /**
99 * Error code
100 */
101 TApplicationExceptionType type_;
102
103};
104
105}} // apache::thrift
106
107#endif // #ifndef _THRIFT_TAPPLICATIONEXCEPTION_H_