diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-02-10 15:43:24 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-02-10 15:43:24 +0900 |
| commit | f0e25121fd66cf97e9c876ded43a419fa86532a9 (patch) | |
| tree | d9c8fa7247dc400800c74a191de864ffcad13fff /mrbgems/mruby-catch/mrblib/catch.rb | |
| parent | 20342714ea2d01687909aea3dbd2d43877e5a571 (diff) | |
| parent | 232e07ad618deff7bb438aa30e86da29b17c37cf (diff) | |
| download | mruby-f0e25121fd66cf97e9c876ded43a419fa86532a9.tar.gz mruby-f0e25121fd66cf97e9c876ded43a419fa86532a9.zip | |
Merge branch 'mruby-catch' of https://github.com/dearblue/mruby into dearblue-mruby-catch
Diffstat (limited to 'mrbgems/mruby-catch/mrblib/catch.rb')
| -rw-r--r-- | mrbgems/mruby-catch/mrblib/catch.rb | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/mrbgems/mruby-catch/mrblib/catch.rb b/mrbgems/mruby-catch/mrblib/catch.rb index 68b165c8d..c69cd125e 100644 --- a/mrbgems/mruby-catch/mrblib/catch.rb +++ b/mrbgems/mruby-catch/mrblib/catch.rb @@ -1,4 +1,4 @@ -class ThrowCatchJump < Exception +class UncaughtThrowError < ArgumentError attr_reader :_tag, :_val def initialize(tag, val) @_tag = tag @@ -9,14 +9,14 @@ end module Kernel def catch(tag=Object.new, &block) - block.call(tag) - rescue ThrowCatchJump => e - unless e._tag.equal?(tag) - raise e - end - return e._val + # A double closure is required to make the nested `catch` distinguishable + # and because `break` goes back to `proc->upper`. + -> { -> { block.call(tag) }.call }.call end def throw(tag, val=nil) - raise ThrowCatchJump.new(tag, val) + __throw(tag, val) + raise UncaughtThrowError.new(tag, val) end + + __preserve_catch_method end |
