You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ro...@apache.org on 2011/08/22 23:38:50 UTC
svn commit: r1160453 -
/thrift/trunk/compiler/cpp/src/generate/t_cpp_generator.cc
Author: roger
Date: Mon Aug 22 21:38:50 2011
New Revision: 1160453
URL: http://svn.apache.org/viewvc?rev=1160453&view=rev
Log:
THRIFT-1269 thrift: handle undeclared exceptions in the async
Modified:
thrift/trunk/compiler/cpp/src/generate/t_cpp_generator.cc
Modified: thrift/trunk/compiler/cpp/src/generate/t_cpp_generator.cc
URL: http://svn.apache.org/viewvc/thrift/trunk/compiler/cpp/src/generate/t_cpp_generator.cc?rev=1160453&r1=1160452&r2=1160453&view=diff
==============================================================================
--- thrift/trunk/compiler/cpp/src/generate/t_cpp_generator.cc (original)
+++ thrift/trunk/compiler/cpp/src/generate/t_cpp_generator.cc Mon Aug 22 21:38:50 2011
@@ -3204,10 +3204,19 @@ void t_cpp_generator::generate_process_f
indent() << " return throw_" << tfunction->get_name() <<
"(cob, seqid, _oprot, ctx, _throw);" << endl <<
indent() << "}" << endl <<
- indent() << " T_GENERIC_PROTOCOL(this, oprot, _oprot);" <<
+ indent() << "T_GENERIC_PROTOCOL(this, oprot, _oprot);" <<
endl << endl;
}
+ // Get the event handler context
+ out <<
+ endl <<
+ indent() << "if (eventHandler_.get() != NULL) {" << endl <<
+ indent() << " ctx = eventHandler_->getContext(\"" << service_func_name << "\", NULL);" << endl <<
+ indent() << "}" << endl <<
+ indent() << "apache::thrift::TProcessorContextFreer freer(eventHandler_.get(), ctx, \"" << service_func_name << "\");" << endl << endl;
+
+ // Throw the TDelayedException, and catch the result
out <<
indent() << tservice->get_name() << "_" << tfunction->get_name() << "_result result;" << endl << endl <<
indent() << "try {" << endl;
@@ -3226,15 +3235,32 @@ void t_cpp_generator::generate_process_f
indent() << "result.__isset." << (*x_iter)->get_name() << " = true;" << endl;
scope_down(out);
}
- // TODO(dreiss): Handle the case where an undeclared exception is thrown?
- // Serialize the result into a struct
+ // Handle the case where an undeclared exception is thrown
+ out << " catch (std::exception& e) {" << endl;
+ indent_up();
out <<
- endl <<
indent() << "if (eventHandler_.get() != NULL) {" << endl <<
- indent() << " ctx = eventHandler_->getContext(\"" << service_func_name << "\", NULL);" << endl <<
+ indent() << " eventHandler_->handlerError(ctx, \"" <<
+ service_func_name << "\");" << endl <<
indent() << "}" << endl <<
- indent() << "::apache::thrift::TProcessorContextFreer freer(eventHandler_.get(), ctx, \"" << service_func_name << "\");" << endl << endl <<
+ endl <<
+ indent() << "apache::thrift::TApplicationException x(e.what());" <<
+ endl <<
+ indent() << "oprot->writeMessageBegin(\"" << tfunction->get_name() <<
+ "\", apache::thrift::protocol::T_EXCEPTION, seqid);" << endl <<
+ indent() << "x.write(oprot);" << endl <<
+ indent() << "oprot->writeMessageEnd();" << endl <<
+ indent() << "oprot->getTransport()->writeEnd();" << endl <<
+ indent() << "oprot->getTransport()->flush();" << endl <<
+ // We pass true to the cob here, since we did successfully write a
+ // response, even though it is an exception response.
+ // It looks like the argument is currently ignored, anyway.
+ indent() << "return cob(true);" << endl;
+ scope_down(out);
+
+ // Serialize the result into a struct
+ out <<
indent() << "if (eventHandler_.get() != NULL) {" << endl <<
indent() << " eventHandler_->preWrite(ctx, \"" << service_func_name << "\");" << endl <<
indent() << "}" << endl << endl <<