| 30 |
ashish |
1 |
/*
|
|
|
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
|
|
|
9 |
*
|
|
|
10 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
11 |
*
|
|
|
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
|
|
|
17 |
* under the License.
|
|
|
18 |
*/
|
|
|
19 |
|
|
|
20 |
#ifndef _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_
|
|
|
21 |
#define _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_ 1
|
|
|
22 |
|
|
|
23 |
#include <string>
|
|
|
24 |
#include <Thrift.h>
|
|
|
25 |
|
|
|
26 |
namespace apache { namespace thrift { namespace transport {
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* Class to encapsulate all the possible types of transport errors that may
|
|
|
30 |
* occur in various transport systems. This provides a sort of generic
|
|
|
31 |
* wrapper around the shitty UNIX E_ error codes that lets a common code
|
|
|
32 |
* base of error handling to be used for various types of transports, i.e.
|
|
|
33 |
* pipes etc.
|
|
|
34 |
*
|
|
|
35 |
*/
|
|
|
36 |
class TTransportException : public apache::thrift::TException {
|
|
|
37 |
public:
|
|
|
38 |
/**
|
|
|
39 |
* Error codes for the various types of exceptions.
|
|
|
40 |
*/
|
|
|
41 |
enum TTransportExceptionType
|
|
|
42 |
{ UNKNOWN = 0
|
|
|
43 |
, NOT_OPEN = 1
|
|
|
44 |
, ALREADY_OPEN = 2
|
|
|
45 |
, TIMED_OUT = 3
|
|
|
46 |
, END_OF_FILE = 4
|
|
|
47 |
, INTERRUPTED = 5
|
|
|
48 |
, BAD_ARGS = 6
|
|
|
49 |
, CORRUPTED_DATA = 7
|
|
|
50 |
, INTERNAL_ERROR = 8
|
|
|
51 |
};
|
|
|
52 |
|
|
|
53 |
TTransportException() :
|
|
|
54 |
apache::thrift::TException(),
|
|
|
55 |
type_(UNKNOWN) {}
|
|
|
56 |
|
|
|
57 |
TTransportException(TTransportExceptionType type) :
|
|
|
58 |
apache::thrift::TException(),
|
|
|
59 |
type_(type) {}
|
|
|
60 |
|
|
|
61 |
TTransportException(const std::string& message) :
|
|
|
62 |
apache::thrift::TException(message),
|
|
|
63 |
type_(UNKNOWN) {}
|
|
|
64 |
|
|
|
65 |
TTransportException(TTransportExceptionType type, const std::string& message) :
|
|
|
66 |
apache::thrift::TException(message),
|
|
|
67 |
type_(type) {}
|
|
|
68 |
|
|
|
69 |
TTransportException(TTransportExceptionType type,
|
|
|
70 |
const std::string& message,
|
|
|
71 |
int errno_copy) :
|
|
|
72 |
apache::thrift::TException(message + ": " + TOutput::strerror_s(errno_copy)),
|
|
|
73 |
type_(type) {}
|
|
|
74 |
|
|
|
75 |
virtual ~TTransportException() throw() {}
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* Returns an error code that provides information about the type of error
|
|
|
79 |
* that has occurred.
|
|
|
80 |
*
|
|
|
81 |
* @return Error code
|
|
|
82 |
*/
|
|
|
83 |
TTransportExceptionType getType() const throw() {
|
|
|
84 |
return type_;
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
virtual const char* what() const throw() {
|
|
|
88 |
if (message_.empty()) {
|
|
|
89 |
switch (type_) {
|
|
|
90 |
case UNKNOWN : return "TTransportException: Unknown transport exception";
|
|
|
91 |
case NOT_OPEN : return "TTransportException: Transport not open";
|
|
|
92 |
case ALREADY_OPEN : return "TTransportException: Transport already open";
|
|
|
93 |
case TIMED_OUT : return "TTransportException: Timed out";
|
|
|
94 |
case END_OF_FILE : return "TTransportException: End of file";
|
|
|
95 |
case INTERRUPTED : return "TTransportException: Interrupted";
|
|
|
96 |
case BAD_ARGS : return "TTransportException: Invalid arguments";
|
|
|
97 |
case CORRUPTED_DATA : return "TTransportException: Corrupted Data";
|
|
|
98 |
case INTERNAL_ERROR : return "TTransportException: Internal error";
|
|
|
99 |
default : return "TTransportException: (Invalid exception type)";
|
|
|
100 |
}
|
|
|
101 |
} else {
|
|
|
102 |
return message_.c_str();
|
|
|
103 |
}
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
protected:
|
|
|
107 |
/** Just like strerror_r but returns a C++ string object. */
|
|
|
108 |
std::string strerror_s(int errno_copy);
|
|
|
109 |
|
|
|
110 |
/** Error code */
|
|
|
111 |
TTransportExceptionType type_;
|
|
|
112 |
|
|
|
113 |
};
|
|
|
114 |
|
|
|
115 |
}}} // apache::thrift::transport
|
|
|
116 |
|
|
|
117 |
#endif // #ifndef _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_
|