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
diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc
index 2f1cf29..5662227 100644
--- a/compiler/cpp/src/generate/t_cpp_generator.cc
+++ b/compiler/cpp/src/generate/t_cpp_generator.cc
@@ -339,8 +339,8 @@
  *
  * @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 @@
  * @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 fdab3ee..f0c7ec2 100644
--- a/compiler/cpp/src/generate/t_cpp_generator.h
+++ b/compiler/cpp/src/generate/t_cpp_generator.h
@@ -34,15 +34,22 @@
    * 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);