From: David Reiss Date: Tue, 26 Feb 2008 06:40:25 +0000 (+0000) Subject: Tighten integration with Ruby exceptions by tying in Exception#message X-Git-Tag: 0.2.0~969 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=0e18224473b8bad918e060900663a9d0058d7196;p=common%2Fthrift.git Tighten integration with Ruby exceptions by tying in Exception#message For Thrift exceptions that contain only a single string field, integrate these even more tightly with Ruby exceptions by aliasing Ruby's Exception#message field with the Thrift field. Ruby exception objects created by Thrift will now display properly in Ruby backtraces, etc. without any special handling by client code. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665503 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/compiler/cpp/src/generate/t_rb_generator.cc b/compiler/cpp/src/generate/t_rb_generator.cc index 7faa7362..bb9c4d1b 100644 --- a/compiler/cpp/src/generate/t_rb_generator.cc +++ b/compiler/cpp/src/generate/t_rb_generator.cc @@ -303,12 +303,18 @@ void t_rb_generator::generate_rb_simple_exception_constructor(std::ofstream& out vector::const_iterator m_iter = members.begin(); if ((*m_iter)->get_type()->is_string()) { + string name = (*m_iter)->get_name(); + indent(out) << "def initialize(message=nil)" << endl; indent_up(); indent(out) << "super()" << endl; - indent(out) << "self." << (*m_iter)->get_name() << " = message" << endl; + indent(out) << "self." << name << " = message" << endl; indent_down(); indent(out) << "end" << endl << endl; + + if (name != "message") { + indent(out) << "def message; " << name << " end" << endl << endl; + } } } }