From 55ff70f8d65ca7f3aa3eaf906d95f82a17be7c92 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Wed, 11 Jun 2008 00:58:25 +0000 Subject: [PATCH] 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 --- lib/alterl/src/thrift_client.erl | 11 +++++++++-- test/cpp/src/TestServer.cpp | 7 ++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/alterl/src/thrift_client.erl b/lib/alterl/src/thrift_client.erl index 5c525327..d76efdfb 100644 --- a/lib/alterl/src/thrift_client.erl +++ b/lib/alterl/src/thrift_client.erl @@ -212,5 +212,12 @@ handle_reply(State = #state{protocol = Proto, 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 14a8a8ef..0c58a297 100644 --- a/test/cpp/src/TestServer.cpp +++ b/test/cpp/src/TestServer.cpp @@ -222,13 +222,18 @@ class TestHandler : public ThriftTestIf { 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; -- 2.17.1