[thrift] gut Erlang exception handling
Summary: * move type field to tException from subclasses
* add backtrace to tException
* add oop:is_a
* on exit, wrap exceptions in {thrift_exception, E} ... otherwise can't distinguish e.g. exit:{{tBinProtException, {tException, ...}}, Stack} vs. exit:{tBinProtException, {tException, ...} -- I hate erlang
* all throws/exits to tException:throw which does the wrapping described above
Reviewed By: eletuchy
Test Plan: been using this code on my live server ^_^
Revert: OK
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665350 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/erl/src/tApplicationException.erl b/lib/erl/src/tApplicationException.erl
index 568b9c9..d99b003 100644
--- a/lib/erl/src/tApplicationException.erl
+++ b/lib/erl/src/tApplicationException.erl
@@ -1,6 +1,6 @@
%%% Copyright (c) 2007- Facebook
%%% Distributed under the Thrift Software License
-%%%
+%%%
%%% See accompanying file LICENSE or visit the Thrift site at:
%%% http://developers.facebook.com/thrift/
@@ -22,9 +22,8 @@
%%% 'super' is required unless ?MODULE is a base class
%%%
-?DEFINE_ATTR(super);
-?DEFINE_ATTR(type).
-
+?DEFINE_ATTR(super).
+
%%%
%%% behavior callbacks
%%%
@@ -38,15 +37,15 @@
%%% inspect(This) -> string()
inspect(This) ->
- ?FORMAT_ATTR(type).
+ "".
%%%
%%% class methods
%%%
new(Type, Message) ->
- Super = (super()):new(Message),
- #?MODULE{super=Super, type=Type}.
+ Super = (super()):new(Type, Message),
+ #?MODULE{super=Super}.
new() -> new(?tApplicationException_UNKNOWN, undefined).
new(Type) -> new(Type, undefined).
@@ -64,49 +63,49 @@
read_while_loop(This, Iprot) ->
{_Fname, Ftype, Fid} = ?R0(Iprot, readFieldBegin),
- if
- Ftype == ?tType_STOP ->
- ok;
+ if
+ Ftype == ?tType_STOP ->
+ ok;
- (Fid == 1) and (Ftype == ?tType_STRING) ->
- Message1 = ?R0(Iprot, readString),
- This1 = oop:set(This, message, Message1),
- ?R0(Iprot, readFieldEnd),
- read_while_loop(This1, Iprot);
+ (Fid == 1) and (Ftype == ?tType_STRING) ->
+ Message1 = ?R0(Iprot, readString),
+ This1 = oop:set(This, message, Message1),
+ ?R0(Iprot, readFieldEnd),
+ read_while_loop(This1, Iprot);
- Fid == 1 ->
- ?R0(Iprot, skip),
- ?R0(Iprot, readFieldEnd),
- read_while_loop(This, Iprot);
+ Fid == 1 ->
+ ?R0(Iprot, skip),
+ ?R0(Iprot, readFieldEnd),
+ read_while_loop(This, Iprot);
- (Fid == 2) and (Ftype == ?tType_I32) ->
- Type1 = ?R0(Iprot, readI32),
- This1 = oop:set(This, type, Type1),
- ?R0(Iprot, readFieldEnd),
- read_while_loop(This1, Iprot);
+ (Fid == 2) and (Ftype == ?tType_I32) ->
+ Type1 = ?R0(Iprot, readI32),
+ This1 = oop:set(This, type, Type1),
+ ?R0(Iprot, readFieldEnd),
+ read_while_loop(This1, Iprot);
- true ->
- ?R0(Iprot, skip),
- ?R0(Iprot, readFieldEnd),
- read_while_loop(This, Iprot)
+ true ->
+ ?R0(Iprot, skip),
+ ?R0(Iprot, readFieldEnd),
+ read_while_loop(This, Iprot)
end.
-write(This, Oprot) ->
+write(This, Oprot) ->
?R1(Oprot, writeStructBegin, "tApplicationException"),
Message = oop:get(This, message),
Type = oop:get(This, type),
- if Message /= undefined ->
- ?R3(Oprot, writeFieldBegin, "message", ?tType_STRING, 1),
- ?R1(Oprot, writeString, Message),
- ?R0(Oprot, writeFieldEnd);
+ if Message /= undefined ->
+ ?R3(Oprot, writeFieldBegin, "message", ?tType_STRING, 1),
+ ?R1(Oprot, writeString, Message),
+ ?R0(Oprot, writeFieldEnd);
true -> ok
end,
- if Type /= undefined ->
- ?R3(Oprot, writeFieldBegin, "type", ?tType_I32, 2),
- ?R1(Oprot, writeI32, Type),
- ?R0(Oprot, writeFieldEnd);
+ if Type /= undefined ->
+ ?R3(Oprot, writeFieldBegin, "type", ?tType_I32, 2),
+ ?R1(Oprot, writeI32, Type),
+ ?R0(Oprot, writeFieldEnd);
true -> ok
end,