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()) {
78 return (std::string("Default Transport Exception: ") +
79 boost::lexical_cast
<std::string
>(type_
)).c_str();
81 return message_
.c_str();
86 /** Just like strerror_r but returns a C++ string object. */
87 std::string
strerror_s(int errno_copy
);
90 TTransportExceptionType type_
;
94 }}} // facebook::thrift::transport
96 #endif // #ifndef _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_