1 // Copyright (c) 2006- Facebook
2 // Distributed under the Thrift Software License
4 // See accompanying file LICENSE or visit the Thrift site at:
5 // http://developers.facebook.com/thrift/
7 #ifndef _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_
8 #define _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_ 1
10 #include <boost/lexical_cast.hpp>
14 namespace facebook
{ namespace thrift
{ namespace transport
{
17 * Class to encapsulate all the possible types of transport errors that may
18 * occur in various transport systems. This provides a sort of generic
19 * wrapper around the shitty UNIX E_ error codes that lets a common code
20 * base of error handling to be used for various types of transports, i.e.
23 * @author Mark Slee <mcslee@facebook.com>
25 class TTransportException
: public facebook::thrift::TException
{
28 * Error codes for the various types of exceptions.
30 enum TTransportExceptionType
{
42 TTransportException() :
43 facebook::thrift::TException(),
46 TTransportException(TTransportExceptionType type
) :
47 facebook::thrift::TException(),
50 TTransportException(const std::string
& message
) :
51 facebook::thrift::TException(message
),
54 TTransportException(TTransportExceptionType type
, const std::string
& message
) :
55 facebook::thrift::TException(message
),
58 TTransportException(TTransportExceptionType type
,
59 const std::string
& message
,
61 facebook::thrift::TException(message
+ ": " + strerror_s(errno_copy
)),
64 virtual ~TTransportException() throw() {}
67 * Returns an error code that provides information about the type of error
72 TTransportExceptionType
getType() {
76 virtual const char* what() const throw() {
77 if (message_
.empty()) {
79 case UNKNOWN
: return "TTransportException: Unknown transport exception";
80 case NOT_OPEN
: return "TTransportException: Transport not open";
81 case ALREADY_OPEN
: return "TTransportException: Transport already open";
82 case TIMED_OUT
: return "TTransportException: Timed out";
83 case END_OF_FILE
: return "TTransportException: End of file";
84 case INTERRUPTED
: return "TTransportException: Interrupted";
85 case BAD_ARGS
: return "TTransportException: Invalid arguments";
86 case CORRUPTED_DATA
: return "TTransportException: Corrupted Data";
87 case INTERNAL_ERROR
: return "TTransportException: Internal error";
88 default : return "TTransportException: (Invalid exception type)";
91 return message_
.c_str();
96 /** Just like strerror_r but returns a C++ string object. */
97 std::string
strerror_s(int errno_copy
);
100 TTransportExceptionType type_
;
104 }}} // facebook::thrift::transport
106 #endif // #ifndef _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_