From ba57274860e05b2738419d462464a699d3ef4463 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 27 Aug 2013 08:18:50 +0000 Subject: timeout.rb: raise given exception * lib/timeout.rb (Timeout#timeout): skip rescue clause only when no exception class is given. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42710 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/timeout.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/timeout.rb b/lib/timeout.rb index 97af8547f4..cf46c1db66 100644 --- a/lib/timeout.rb +++ b/lib/timeout.rb @@ -62,7 +62,9 @@ module Timeout # a module method, so you can call it directly as Timeout.timeout(). def timeout(sec, klass = nil) #:yield: +sec+ return yield(sec) if sec == nil or sec.zero? - bt = catch(ExitException.new) do |exception| + message = "execution expired" + e = Error + bt = catch((klass||ExitException).new) do |exception| begin x = Thread.current y = Thread.start { @@ -71,11 +73,12 @@ module Timeout rescue => e x.raise e else - # no message, not to make new instance. - x.raise exception + x.raise exception, message end } return yield(sec) + rescue (klass||ExitException) => e + e.backtrace ensure if y y.kill @@ -89,7 +92,7 @@ module Timeout while THIS_FILE =~ bt[level] bt.delete_at(level) end - raise((klass||Error), "execution expired", bt) + raise(e, message, bt) end module_function :timeout -- cgit v1.2.3