From 3e9e4a6a96758a3bfbdf7054419a054f00c1d6b6 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 8 Jan 2014 04:12:39 +0000 Subject: lib/timeout.rb: fallback to Timeout::Error * lib/timeout.rb (Timeout::ExitException.catch): pass arguments for new instance. * lib/timeout.rb (Timeout::ExitException#exception): fallback to Timeout::Error if couldn't throw. [ruby-dev:47872] [Bug #9380] * lib/timeout.rb (Timeout#timeout): initialize ExitException with message for the fallback case. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44523 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/timeout.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'lib/timeout.rb') diff --git a/lib/timeout.rb b/lib/timeout.rb index 441f8d4236..d805dce2a3 100644 --- a/lib/timeout.rb +++ b/lib/timeout.rb @@ -28,15 +28,23 @@ module Timeout class ExitException < ::Exception # :nodoc: attr_reader :thread - def self.catch - exc = new + def self.catch(*args) + exc = new(*args) exc.instance_variable_set(:@thread, Thread.current) exc.freeze ::Kernel.catch(exc) {yield exc} end def exception(*) - throw(self, caller) if self.thread == Thread.current + if self.thread == Thread.current + bt = caller + begin + throw(self, bt) + rescue ArgumentError => e + raise unless e.message.start_with?("uncaught throw") + raise Error, message, backtrace + end + end self end end @@ -95,7 +103,7 @@ module Timeout bt = e.backtrace end else - bt = ExitException.catch(&bl) + bt = ExitException.catch(message, &bl) end rej = /\A#{Regexp.quote(__FILE__)}:#{__LINE__-4}\z/o bt.reject! {|m| rej =~ m} -- cgit v1.2.3