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