File indexing completed on 2026-04-17 08:35:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #ifndef _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_
0021 #define _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_ 1
0022
0023 #include <boost/numeric/conversion/cast.hpp>
0024 #include <string>
0025 #include <thrift/Thrift.h>
0026
0027 namespace apache {
0028 namespace thrift {
0029 namespace transport {
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 class TTransportException : public apache::thrift::TException {
0040 public:
0041
0042
0043
0044 enum TTransportExceptionType {
0045 UNKNOWN = 0,
0046 NOT_OPEN = 1,
0047 TIMED_OUT = 2,
0048 END_OF_FILE = 3,
0049 INTERRUPTED = 4,
0050 BAD_ARGS = 5,
0051 CORRUPTED_DATA = 6,
0052 INTERNAL_ERROR = 7,
0053 CLIENT_DISCONNECT = 8
0054 };
0055
0056 TTransportException() : apache::thrift::TException(), type_(UNKNOWN) {}
0057
0058 TTransportException(TTransportExceptionType type) : apache::thrift::TException(), type_(type) {}
0059
0060 TTransportException(const std::string& message)
0061 : apache::thrift::TException(message), type_(UNKNOWN) {}
0062
0063 TTransportException(TTransportExceptionType type, const std::string& message)
0064 : apache::thrift::TException(message), type_(type) {}
0065
0066 TTransportException(TTransportExceptionType type, const std::string& message, int errno_copy)
0067 : apache::thrift::TException(message + ": " + TOutput::strerror_s(errno_copy)), type_(type) {}
0068
0069 ~TTransportException() noexcept override = default;
0070
0071
0072
0073
0074
0075
0076
0077 TTransportExceptionType getType() const noexcept { return type_; }
0078
0079 const char* what() const noexcept override;
0080
0081 protected:
0082
0083 std::string strerror_s(int errno_copy);
0084
0085
0086 TTransportExceptionType type_;
0087 };
0088
0089
0090
0091
0092
0093 template <typename To, typename From> To safe_numeric_cast(From i) {
0094 try {
0095 return boost::numeric_cast<To>(i);
0096 }
0097 catch (const std::bad_cast& bc) {
0098 throw TTransportException(TTransportException::CORRUPTED_DATA,
0099 bc.what());
0100 }
0101 }
0102
0103 }
0104 }
0105 }
0106
0107 #endif