Subversion Repositories SmartDukaan

Rev

Rev 30 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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_PROTOCOL_TPROTOCOLEXCEPTION_H_
21
#define _THRIFT_PROTOCOL_TPROTOCOLEXCEPTION_H_ 1
22
 
23
#include <string>
24
 
25
namespace apache { namespace thrift { namespace protocol {
26
 
27
/**
28
 * Class to encapsulate all the possible types of protocol errors that may
29
 * occur in various protocol systems. This provides a sort of generic
30
 * wrapper around the shitty UNIX E_ error codes that lets a common code
31
 * base of error handling to be used for various types of protocols, i.e.
32
 * pipes etc.
33
 *
34
 */
35
class TProtocolException : public apache::thrift::TException {
36
 public:
37
 
38
  /**
39
   * Error codes for the various types of exceptions.
40
   */
41
  enum TProtocolExceptionType
42
  { UNKNOWN = 0
43
  , INVALID_DATA = 1
44
  , NEGATIVE_SIZE = 2
45
  , SIZE_LIMIT = 3
46
  , BAD_VERSION = 4
47
  , NOT_IMPLEMENTED = 5
48
  };
49
 
50
  TProtocolException() :
51
    apache::thrift::TException(),
52
    type_(UNKNOWN) {}
53
 
54
  TProtocolException(TProtocolExceptionType type) :
55
    apache::thrift::TException(),
56
    type_(type) {}
57
 
58
  TProtocolException(const std::string& message) :
59
    apache::thrift::TException(message),
60
    type_(UNKNOWN) {}
61
 
62
  TProtocolException(TProtocolExceptionType type, const std::string& message) :
63
    apache::thrift::TException(message),
64
    type_(type) {}
65
 
66
  virtual ~TProtocolException() throw() {}
67
 
68
  /**
69
   * Returns an error code that provides information about the type of error
70
   * that has occurred.
71
   *
72
   * @return Error code
73
   */
74
  TProtocolExceptionType getType() {
75
    return type_;
76
  }
77
 
78
  virtual const char* what() const throw() {
79
    if (message_.empty()) {
80
      switch (type_) {
81
        case UNKNOWN         : return "TProtocolException: Unknown protocol exception";
82
        case INVALID_DATA    : return "TProtocolException: Invalid data";
83
        case NEGATIVE_SIZE   : return "TProtocolException: Negative size";
84
        case SIZE_LIMIT      : return "TProtocolException: Exceeded size limit";
85
        case BAD_VERSION     : return "TProtocolException: Invalid version";
86
        case NOT_IMPLEMENTED : return "TProtocolException: Not implemented";
87
        default              : return "TProtocolException: (Invalid exception type)";
88
      }
89
    } else {
90
      return message_.c_str();
91
    }
92
  }
93
 
94
 protected:
95
  /**
96
   * Error code
97
   */
98
  TProtocolExceptionType type_;
99
 
100
};
101
 
102
}}} // apache::thrift::protocol
103
 
104
#endif // #ifndef _THRIFT_PROTOCOL_TPROTOCOLEXCEPTION_H_