Back to home page

EIC code displayed by LXR

 
 

    


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

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_PROTOCOL_TPROTOCOLEXCEPTION_H_
0021 #define _THRIFT_PROTOCOL_TPROTOCOLEXCEPTION_H_ 1
0022 
0023 #include <string>
0024 
0025 namespace apache {
0026 namespace thrift {
0027 namespace protocol {
0028 
0029 /**
0030  * Class to encapsulate all the possible types of protocol errors that may
0031  * occur in various protocol systems. This provides a sort of generic
0032  * wrapper around the vague UNIX E_ error codes that lets a common code
0033  * base of error handling to be used for various types of protocols, i.e.
0034  * pipes etc.
0035  *
0036  */
0037 class TProtocolException : public apache::thrift::TException {
0038 public:
0039   /**
0040    * Error codes for the various types of exceptions.
0041    */
0042   enum TProtocolExceptionType {
0043     UNKNOWN = 0,
0044     INVALID_DATA = 1,
0045     NEGATIVE_SIZE = 2,
0046     SIZE_LIMIT = 3,
0047     BAD_VERSION = 4,
0048     NOT_IMPLEMENTED = 5,
0049     DEPTH_LIMIT = 6
0050   };
0051 
0052   TProtocolException() : apache::thrift::TException(), type_(UNKNOWN) {}
0053 
0054   TProtocolException(TProtocolExceptionType type) : apache::thrift::TException(), type_(type) {}
0055 
0056   TProtocolException(const std::string& message)
0057     : apache::thrift::TException(message), type_(UNKNOWN) {}
0058 
0059   TProtocolException(TProtocolExceptionType type, const std::string& message)
0060     : apache::thrift::TException(message), type_(type) {}
0061 
0062   ~TProtocolException() noexcept override = default;
0063 
0064   /**
0065    * Returns an error code that provides information about the type of error
0066    * that has occurred.
0067    *
0068    * @return Error code
0069    */
0070   TProtocolExceptionType getType() const { return type_; }
0071 
0072   const char* what() const noexcept override {
0073     if (message_.empty()) {
0074       switch (type_) {
0075       case UNKNOWN:
0076         return "TProtocolException: Unknown protocol exception";
0077       case INVALID_DATA:
0078         return "TProtocolException: Invalid data";
0079       case NEGATIVE_SIZE:
0080         return "TProtocolException: Negative size";
0081       case SIZE_LIMIT:
0082         return "TProtocolException: Exceeded size limit";
0083       case BAD_VERSION:
0084         return "TProtocolException: Invalid version";
0085       case NOT_IMPLEMENTED:
0086         return "TProtocolException: Not implemented";
0087       case DEPTH_LIMIT:
0088         return "TProtocolException: Exceeded depth limit";
0089       default:
0090         return "TProtocolException: (Invalid exception type)";
0091       }
0092     } else {
0093       return message_.c_str();
0094     }
0095   }
0096 
0097 protected:
0098   /**
0099    * Error code
0100    */
0101   TProtocolExceptionType type_;
0102 };
0103 }
0104 }
0105 } // apache::thrift::protocol
0106 
0107 #endif // #ifndef _THRIFT_PROTOCOL_TPROTOCOLEXCEPTION_H_