From 971fda34b5756b2cdea87d467aa45276ab1aad8c Mon Sep 17 00:00:00 2001 From: Mark Slee Date: Fri, 15 Dec 2006 19:07:04 +0000 Subject: [PATCH] All user-defined thrift exceptions inherit from TException Summary: So you can catch more effectively Reviewed By: tbr-karl git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664896 13f79535-47bb-0310-9956-ffa450edef68 --- compiler/cpp/src/generate/t_cpp_generator.cc | 14 ++++++++++---- compiler/cpp/src/generate/t_cpp_generator.h | 17 ++++++++++++----- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc index 2f1cf293..5662227f 100644 --- a/compiler/cpp/src/generate/t_cpp_generator.cc +++ b/compiler/cpp/src/generate/t_cpp_generator.cc @@ -339,8 +339,8 @@ string t_cpp_generator::render_const_value(ofstream& out, string name, t_type* t * * @param tstruct The struct definition */ -void t_cpp_generator::generate_struct(t_struct* tstruct) { - generate_struct_definition(f_types_, tstruct); +void t_cpp_generator::generate_cpp_struct(t_struct* tstruct, bool is_exception) { + generate_struct_definition(f_types_, tstruct, is_exception); generate_struct_reader(f_types_impl_, tstruct); generate_struct_writer(f_types_impl_, tstruct); } @@ -352,10 +352,16 @@ void t_cpp_generator::generate_struct(t_struct* tstruct) { * @param tstruct The struct */ void t_cpp_generator::generate_struct_definition(ofstream& out, - t_struct* tstruct) { + t_struct* tstruct, + bool is_exception) { + string extends = ""; + if (is_exception) { + extends = " : public facebook::thrift::TException"; + } + // Open struct def out << - indent() << "class " << tstruct->get_name() << " {" << endl << + indent() << "class " << tstruct->get_name() << extends << " {" << endl << indent() << " public:" << endl << endl; indent_up(); diff --git a/compiler/cpp/src/generate/t_cpp_generator.h b/compiler/cpp/src/generate/t_cpp_generator.h index fdab3eea..f0c7ec27 100644 --- a/compiler/cpp/src/generate/t_cpp_generator.h +++ b/compiler/cpp/src/generate/t_cpp_generator.h @@ -34,15 +34,22 @@ class t_cpp_generator : public t_oop_generator { * Program-level generation functions */ - void generate_typedef (t_typedef* ttypedef); - void generate_enum (t_enum* tenum); - void generate_struct (t_struct* tstruct); - void generate_service (t_service* tservice); + void generate_typedef(t_typedef* ttypedef); + void generate_enum(t_enum* tenum); + void generate_struct(t_struct* tstruct) { + generate_cpp_struct(tstruct, false); + } + void generate_xception(t_struct* txception) { + generate_cpp_struct(txception, true); + } + void generate_cpp_struct(t_struct* tstruct, bool is_exception); + + void generate_service(t_service* tservice); void print_const_value(std::ofstream& out, std::string name, t_type* type, t_const_value* value); std::string render_const_value(std::ofstream& out, std::string name, t_type* type, t_const_value* value); - void generate_struct_definition (std::ofstream& out, t_struct* tstruct); + void generate_struct_definition (std::ofstream& out, t_struct* tstruct, bool is_exception=false); void generate_struct_reader (std::ofstream& out, t_struct* tstruct); void generate_struct_writer (std::ofstream& out, t_struct* tstruct); void generate_struct_result_writer (std::ofstream& out, t_struct* tstruct); -- 2.17.1