blob: b9c0d3d6ef969ab3cd83f3303673d3415dd66e3d [file] [log] [blame]
Mark Slee3d424402007-02-21 04:17:34 +00001package com.facebook.thrift;
2
3import com.facebook.thrift.protocol.TField;
4import com.facebook.thrift.protocol.TProtocol;
5import com.facebook.thrift.protocol.TProtocolUtil;
6import com.facebook.thrift.protocol.TStruct;
7import com.facebook.thrift.protocol.TType;
8
9/**
10 * Application level exception
11 *
12 * @author Mark Slee <mcslee@facebook.com>
13 */
14public class TApplicationException extends TException {
15
16 public static final int UNKNOWN = 0;
17 public static final int UNKNOWN_METHOD = 1;
18 public static final int INVALID_MESSAGE_TYPE = 2;
19 public static final int WRONG_METHOD_NAME = 3;
20 public static final int BAD_SEQUENCE_ID = 4;
21 public static final int MISSING_RESULT = 5;
22
Mark Sleeb46c0412007-02-21 04:54:38 +000023 protected int type_ = UNKNOWN;
Mark Slee3d424402007-02-21 04:17:34 +000024
25 public TApplicationException() {
26 super();
27 }
28
29 public TApplicationException(int type) {
30 super();
31 type_ = type;
32 }
33
34 public TApplicationException(int type, String message) {
35 super(message);
36 type_ = type;
37 }
38
39 public TApplicationException(String message) {
40 super(message);
41 }
42
43 public int getType() {
44 return type_;
45 }
46
47 public static TApplicationException read(TProtocol iprot) throws TException {
48 TField field;
49 TStruct struct = iprot.readStructBegin();
50
51 String message = null;
52 int type = UNKNOWN;
53
54 while (true) {
55 field = iprot.readFieldBegin();
56 if (field.type == TType.STOP) {
57 break;
58 }
59 switch (field.id) {
60 case 1:
61 if (field.type == TType.STRING) {
62 message = iprot.readString();
63 } else {
64 TProtocolUtil.skip(iprot, field.type);
65 }
66 break;
67 case 2:
68 if (field.type == TType.I32) {
69 type = iprot.readI32();
70 } else {
71 TProtocolUtil.skip(iprot, field.type);
72 }
73 break;
74 default:
75 TProtocolUtil.skip(iprot, field.type);
76 break;
77 }
78 iprot.readFieldEnd();
79 }
80 iprot.readStructEnd();
81
82 return new TApplicationException(type, message);
83 }
84
85 public void write(TProtocol oprot) throws TException {
86 TStruct struct = new TStruct("TApplicationException");
87 TField field = new TField();
88 oprot.writeStructBegin(struct);
89 if (getMessage() != null) {
90 field.name = "message";
91 field.type = TType.STRING;
92 field.id = 1;
93 oprot.writeFieldBegin(field);
94 oprot.writeString(getMessage());
95 oprot.writeFieldEnd();
96 }
97 field.name = "type";
98 field.type = TType.I32;
99 field.id = 2;
100 oprot.writeFieldBegin(field);
101 oprot.writeI32(type_);
102 oprot.writeFieldEnd();
103 oprot.writeFieldStop();
104 oprot.writeStructEnd();
105
106 }
107}