diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-27 08:18:50 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-27 08:18:50 +0000 |
commit | ba57274860e05b2738419d462464a699d3ef4463 (patch) | |
tree | c7eac92dd5a9feedbe402d83a9f2f500bc8c171c /lib/timeout.rb | |
parent | 8ef0192103f9edc4a7193f635a27206b56944637 (diff) | |
download | ruby-ba57274860e05b2738419d462464a699d3ef4463.tar.gz |
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
Diffstat (limited to 'lib/timeout.rb')
-rw-r--r-- | lib/timeout.rb | 11 |
1 files changed, 7 insertions, 4 deletions
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 |