Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 08:35:04

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one
0003  * or more contributor license agreements. See the NOTICE file
0004  * distributed with this work for additional information
0005  * regarding copyright ownership. The ASF licenses this file
0006  * to you under the Apache License, Version 2.0 (the
0007  * "License"); you may not use this file except in compliance
0008  * with the License. You may obtain a copy of the License at
0009  *
0010  *   http://www.apache.org/licenses/LICENSE-2.0
0011  *
0012  * Unless required by applicable law or agreed to in writing,
0013  * software distributed under the License is distributed on an
0014  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0015  * KIND, either express or implied. See the License for the
0016  * specific language governing permissions and limitations
0017  * under the License.
0018  */
0019 
0020 #ifndef _THRIFT_TAPPLICATIONEXCEPTION_H_
0021 #define _THRIFT_TAPPLICATIONEXCEPTION_H_ 1
0022 
0023 #include <thrift/Thrift.h>
0024 
0025 namespace apache {
0026 namespace thrift {
0027 
0028 namespace protocol {
0029 class TProtocol;
0030 }
0031 
0032 class TApplicationException : public TException {
0033 public:
0034   /**
0035    * Error codes for the various types of exceptions.
0036    */
0037   enum TApplicationExceptionType {
0038     UNKNOWN = 0,
0039     UNKNOWN_METHOD = 1,
0040     INVALID_MESSAGE_TYPE = 2,
0041     WRONG_METHOD_NAME = 3,
0042     BAD_SEQUENCE_ID = 4,
0043     MISSING_RESULT = 5,
0044     INTERNAL_ERROR = 6,
0045     PROTOCOL_ERROR = 7,
0046     INVALID_TRANSFORM = 8,
0047     INVALID_PROTOCOL = 9,
0048     UNSUPPORTED_CLIENT_TYPE = 10
0049   };
0050 
0051   TApplicationException() : TException(), type_(UNKNOWN) {}
0052 
0053   TApplicationException(TApplicationExceptionType type) : TException(), type_(type) {}
0054 
0055   TApplicationException(const std::string& message) : TException(message), type_(UNKNOWN) {}
0056 
0057   TApplicationException(TApplicationExceptionType type, const std::string& message)
0058     : TException(message), type_(type) {}
0059 
0060   ~TApplicationException() noexcept override = default;
0061 
0062   /**
0063    * Returns an error code that provides information about the type of error
0064    * that has occurred.
0065    *
0066    * @return Error code
0067    */
0068   TApplicationExceptionType getType() const { return type_; }
0069 
0070   const char* what() const noexcept override {
0071     if (message_.empty()) {
0072       switch (type_) {
0073       case UNKNOWN:
0074         return "TApplicationException: Unknown application exception";
0075       case UNKNOWN_METHOD:
0076         return "TApplicationException: Unknown method";
0077       case INVALID_MESSAGE_TYPE:
0078         return "TApplicationException: Invalid message type";
0079       case WRONG_METHOD_NAME:
0080         return "TApplicationException: Wrong method name";
0081       case BAD_SEQUENCE_ID:
0082         return "TApplicationException: Bad sequence identifier";
0083       case MISSING_RESULT:
0084         return "TApplicationException: Missing result";
0085       case INTERNAL_ERROR:
0086         return "TApplicationException: Internal error";
0087       case PROTOCOL_ERROR:
0088         return "TApplicationException: Protocol error";
0089       case INVALID_TRANSFORM:
0090         return "TApplicationException: Invalid transform";
0091       case INVALID_PROTOCOL:
0092         return "TApplicationException: Invalid protocol";
0093       case UNSUPPORTED_CLIENT_TYPE:
0094         return "TApplicationException: Unsupported client type";
0095       default:
0096         return "TApplicationException: (Invalid exception type)";
0097       };
0098     } else {
0099       return message_.c_str();
0100     }
0101   }
0102 
0103   uint32_t read(protocol::TProtocol* iprot);
0104   uint32_t write(protocol::TProtocol* oprot) const;
0105 
0106 protected:
0107   /**
0108    * Error code
0109    */
0110   TApplicationExceptionType type_;
0111 };
0112 }
0113 } // apache::thrift
0114 
0115 #endif // #ifndef _THRIFT_TAPPLICATIONEXCEPTION_H_