From: Jason Roelofs Date: 2007-09-01T02:44:21+09:00 Subject: Re: Overriding Kernel#raise ------=_Part_6081_30284550.1188582260355 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline The splat operator is your friend: module Kernel alias _raise raise def raise(*a) begin _raise(*a) rescue Exception => e $stderr.print e.class, ": ", e.message, "\n" $stderr.puts e.backtrace unless e.backtrace.nil? end end end As I've never done this or seen it done, I'm not sure how well it will work, but for your needs this looks fine. Jason On 8/31/07, Shane Liesegang wrote: > > I'm writing a C++ program that has a Ruby interpreter embedded in it. > I'd like to keep all Ruby-related exceptions contained within the Ruby > runtime so that I don't have to protect all my calls. Since native > objects can be subclassed by Ruby, you never know when a call is going > to result in the interpreter doing something. > > To contain the exceptions, I've overridden Kernel#raise, like this: > > module Kernel > alias _raise raise > > def raise(*a) > begin > if a.size == 0 > _raise > elsif a.size == 1 > _raise(a[0]) > else > _raise(a[0], a[1]) > end > rescue Exception => e > $stderr.print e.class, ": ", e.message, "\n" > $stderr.puts e.backtrace unless e.backtrace.nil? > end > end > end > > I can't shake the feeling that this is *dirty* and that there must be a > better way to do things. Just hoping to get some feedback on both the > concept and implementation. > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_6081_30284550.1188582260355--