Commit 3bdd53d3
3bdd53d3a6c3Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 2 files · +1 added · ~1 modified
Description
Add catch/throw
catch(:tag) { block } → setjmp, run block, match tag on longjmp throw :tag, value → set tag+value, longjmp with code 2
Features:
- Nested catch: inner re-throws to outer if tag doesn't match
- catch without throw returns block's last expression
- throw in both statement and expression context
- Integer and string throw values
Test: examples/bm_catch.rb — basic, nested, and no-throw cases.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 3bdd53d3a6c3
- Parent
- a154ae57b25c
examples/bm_catch.rbaddedView file
1+
# Test catch/throw2+
3+
result = catch(:done) do4+
throw :done, 425+
999 # unreachable6+
end7+
puts result # 428+
9+
# catch without throw returns block value10+
result2 = catch(:nope) do11+
10012+
end13+
puts result2 # 10014+
15+
# Nested catch (same type)16+
result3 = catch(:outer) do17+
catch(:inner) do18+
throw :outer, 7719+
end20+
021+
end22+
puts result3 # 7723+
24+
puts "done"src/codegen.cmodifiedView file
Loading diff…