David Reiss | ac110e4 | 2010-03-09 05:20:07 +0000 | [diff] [blame] | 1 | /* |
| 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 Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 23 | #include <thrift/Thrift.h> |
David Reiss | ac110e4 | 2010-03-09 05:20:07 +0000 | [diff] [blame] | 24 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 25 | namespace apache { |
| 26 | namespace thrift { |
David Reiss | ac110e4 | 2010-03-09 05:20:07 +0000 | [diff] [blame] | 27 | |
| 28 | namespace protocol { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 29 | class TProtocol; |
David Reiss | ac110e4 | 2010-03-09 05:20:07 +0000 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | class TApplicationException : public TException { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 33 | public: |
David Reiss | ac110e4 | 2010-03-09 05:20:07 +0000 | [diff] [blame] | 34 | /** |
| 35 | * Error codes for the various types of exceptions. |
| 36 | */ |
| 37 | enum TApplicationExceptionType { |
| 38 | UNKNOWN = 0, |
| 39 | UNKNOWN_METHOD = 1, |
| 40 | INVALID_MESSAGE_TYPE = 2, |
| 41 | WRONG_METHOD_NAME = 3, |
| 42 | BAD_SEQUENCE_ID = 4, |
Roger Meier | 345ecc7 | 2011-08-03 09:49:27 +0000 | [diff] [blame] | 43 | MISSING_RESULT = 5, |
| 44 | INTERNAL_ERROR = 6, |
Roger Meier | 0193149 | 2012-12-22 21:31:03 +0100 | [diff] [blame] | 45 | PROTOCOL_ERROR = 7, |
| 46 | INVALID_TRANSFORM = 8, |
| 47 | INVALID_PROTOCOL = 9, |
| 48 | UNSUPPORTED_CLIENT_TYPE = 10 |
David Reiss | ac110e4 | 2010-03-09 05:20:07 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 51 | TApplicationException() : TException(), type_(UNKNOWN) {} |
David Reiss | ac110e4 | 2010-03-09 05:20:07 +0000 | [diff] [blame] | 52 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 53 | TApplicationException(TApplicationExceptionType type) : TException(), type_(type) {} |
David Reiss | ac110e4 | 2010-03-09 05:20:07 +0000 | [diff] [blame] | 54 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 55 | TApplicationException(const std::string& message) : TException(message), type_(UNKNOWN) {} |
David Reiss | ac110e4 | 2010-03-09 05:20:07 +0000 | [diff] [blame] | 56 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 57 | TApplicationException(TApplicationExceptionType type, const std::string& message) |
| 58 | : TException(message), type_(type) {} |
David Reiss | ac110e4 | 2010-03-09 05:20:07 +0000 | [diff] [blame] | 59 | |
cyy | 7b93559 | 2019-01-05 10:04:25 +0800 | [diff] [blame] | 60 | virtual ~TApplicationException() noexcept {} |
David Reiss | ac110e4 | 2010-03-09 05:20:07 +0000 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * Returns an error code that provides information about the type of error |
| 64 | * that has occurred. |
| 65 | * |
| 66 | * @return Error code |
| 67 | */ |
tpcwang | d42d8be | 2016-03-24 09:56:10 -0700 | [diff] [blame] | 68 | TApplicationExceptionType getType() const { return type_; } |
David Reiss | ac110e4 | 2010-03-09 05:20:07 +0000 | [diff] [blame] | 69 | |
cyy | 7b93559 | 2019-01-05 10:04:25 +0800 | [diff] [blame] | 70 | virtual const char* what() const noexcept { |
David Reiss | ac110e4 | 2010-03-09 05:20:07 +0000 | [diff] [blame] | 71 | if (message_.empty()) { |
| 72 | switch (type_) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 73 | case UNKNOWN: |
| 74 | return "TApplicationException: Unknown application exception"; |
| 75 | case UNKNOWN_METHOD: |
| 76 | return "TApplicationException: Unknown method"; |
| 77 | case INVALID_MESSAGE_TYPE: |
| 78 | return "TApplicationException: Invalid message type"; |
| 79 | case WRONG_METHOD_NAME: |
| 80 | return "TApplicationException: Wrong method name"; |
| 81 | case BAD_SEQUENCE_ID: |
| 82 | return "TApplicationException: Bad sequence identifier"; |
| 83 | case MISSING_RESULT: |
| 84 | return "TApplicationException: Missing result"; |
| 85 | case INTERNAL_ERROR: |
| 86 | return "TApplicationException: Internal error"; |
| 87 | case PROTOCOL_ERROR: |
| 88 | return "TApplicationException: Protocol error"; |
| 89 | case INVALID_TRANSFORM: |
| 90 | return "TApplicationException: Invalid transform"; |
| 91 | case INVALID_PROTOCOL: |
| 92 | return "TApplicationException: Invalid protocol"; |
| 93 | case UNSUPPORTED_CLIENT_TYPE: |
| 94 | return "TApplicationException: Unsupported client type"; |
| 95 | default: |
| 96 | return "TApplicationException: (Invalid exception type)"; |
David Reiss | ac110e4 | 2010-03-09 05:20:07 +0000 | [diff] [blame] | 97 | }; |
| 98 | } else { |
| 99 | return message_.c_str(); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | uint32_t read(protocol::TProtocol* iprot); |
| 104 | uint32_t write(protocol::TProtocol* oprot) const; |
| 105 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 106 | protected: |
David Reiss | ac110e4 | 2010-03-09 05:20:07 +0000 | [diff] [blame] | 107 | /** |
| 108 | * Error code |
| 109 | */ |
| 110 | TApplicationExceptionType type_; |
David Reiss | ac110e4 | 2010-03-09 05:20:07 +0000 | [diff] [blame] | 111 | }; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 112 | } |
| 113 | } // apache::thrift |
David Reiss | ac110e4 | 2010-03-09 05:20:07 +0000 | [diff] [blame] | 114 | |
| 115 | #endif // #ifndef _THRIFT_TAPPLICATIONEXCEPTION_H_ |