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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
20 #ifndef _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_
21 #define _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_ 1
23 #include <boost/numeric/conversion/cast.hpp>
25 #include <thrift/Thrift.h>
32 * Class to encapsulate all the possible types of transport errors that may
33 * occur in various transport systems. This provides a sort of generic
34 * wrapper around the vague UNIX E_ error codes that lets a common code
35 * base of error handling to be used for various types of transports, i.e.
39 class TTransportException
: public apache::thrift::TException
{
42 * Error codes for the various types of exceptions.
44 enum TTransportExceptionType
{
55 TTransportException() : apache::thrift::TException(), type_(UNKNOWN
) {}
57 TTransportException(TTransportExceptionType type
) : apache::thrift::TException(), type_(type
) {}
59 TTransportException(const std::string
& message
)
60 : apache::thrift::TException(message
), type_(UNKNOWN
) {}
62 TTransportException(TTransportExceptionType type
, const std::string
& message
)
63 : apache::thrift::TException(message
), type_(type
) {}
65 TTransportException(TTransportExceptionType type
, const std::string
& message
, int errno_copy
)
66 : apache::thrift::TException(message
+ ": " + TOutput::strerror_s(errno_copy
)), type_(type
) {}
68 ~TTransportException() noexcept override
= default;
71 * Returns an error code that provides information about the type of error
76 TTransportExceptionType
getType() const noexcept
{ return type_
; }
78 const char* what() const noexcept override
;
81 /** Just like strerror_r but returns a C++ string object. */
82 std::string
strerror_s(int errno_copy
);
85 TTransportExceptionType type_
;
89 * Legacy code in transport implementations have overflow issues
90 * that need to be enforced.
92 template <typename To
, typename From
> To
safe_numeric_cast(From i
) {
94 return boost::numeric_cast
<To
>(i
);
96 catch (const std::bad_cast
& bc
) {
97 throw TTransportException(TTransportException::CORRUPTED_DATA
,
104 } // apache::thrift::transport
106 #endif // #ifndef _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_