From 0e18224473b8bad918e060900663a9d0058d7196 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Tue, 26 Feb 2008 06:40:25 +0000 Subject: [PATCH] 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 --- compiler/cpp/src/generate/t_rb_generator.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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; + } } } } -- 2.17.1