Implement TApplicationException handling in alt_erl client

Summary:
  Throws a 'TApplicationException' record

Test plan:
  Changed cpp TestServer so that if testException is called with "ApplicationException" as an argument, it throws a TException which is serialized back as an EXCEPTION type message


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@666421 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/alterl/src/thrift_client.erl b/lib/alterl/src/thrift_client.erl
index 5c52532..d76efdf 100644
--- a/lib/alterl/src/thrift_client.erl
+++ b/lib/alterl/src/thrift_client.erl
@@ -212,5 +212,12 @@
     Result.
                      
 
-handle_application_exception(_State) ->
-    not_yet_impl.
+handle_application_exception(State = #state{protocol = Proto}) ->
+    {ok, Exception} = thrift_protocol:read(Proto,
+                                           ?TApplicationException_Structure),
+    ok = thrift_protocol:read(Proto, message_end),
+    XRecord = list_to_tuple(
+                ['TApplicationException' | tuple_to_list(Exception)]),
+    io:format("X: ~p~n", [XRecord]),
+    true = is_record(XRecord, 'TApplicationException'),
+    {exception, XRecord}.
diff --git a/test/cpp/src/TestServer.cpp b/test/cpp/src/TestServer.cpp
index 14a8a8e..0c58a29 100644
--- a/test/cpp/src/TestServer.cpp
+++ b/test/cpp/src/TestServer.cpp
@@ -222,13 +222,18 @@
     hello.i64_thing = (int64_t)arg2;
   }
 
-  void testException(const std::string &arg) throw(Xception) {
+  void testException(const std::string &arg)
+    throw(Xception, facebook::thrift::TException)
+  {
     printf("testException(%s)\n", arg.c_str());
     if (arg.compare("Xception") == 0) {
       Xception e;
       e.errorCode = 1001;
       e.message = "This is an Xception";
       throw e;
+    } else if (arg.compare("ApplicationException") == 0) {
+      facebook::thrift::TException e;
+      throw e;
     } else {
       Xtruct result;
       result.string_thing = arg;