Commit 583eeebe
583eeebe16e0Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 2 files · +1 added · ~1 modified
Description
Add exception class hierarchy: raise ClassName, rescue ClassName
- raise ClassName, "msg" → sp_raise_cls(class, msg)
- rescue ClassName => e → sp_exc_is_a(class) with inheritance check
- Multiple rescue clauses (rescue A; rescue B) → if/else if chain
- Exception class inheritance resolved at compile time from class registry
- sp_exc_class tracks the raised exception's class name
Category 9 (exception hierarchy) — done for class-based raise/rescue.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 583eeebe16e0
- Parent
- 4fd787f5c6d5
examples/bm_exceptions.rbaddedView file
1+
# Test exception classes2+
3+
class AppError < RuntimeError4+
end5+
6+
class NotFoundError < AppError7+
end8+
9+
# Raise custom exception10+
begin11+
raise NotFoundError, "item not found"12+
rescue NotFoundError => e13+
puts e # item not found14+
rescue AppError => e15+
puts "app error"16+
end17+
18+
# Raise with class name19+
begin20+
raise AppError, "something went wrong"21+
rescue NotFoundError => e22+
puts "not found"23+
rescue AppError => e24+
puts e # something went wrong25+
end26+
27+
# Bare rescue catches all28+
begin29+
raise "generic error"30+
rescue => e31+
puts e # generic error32+
end33+
34+
puts "done"src/codegen.cmodifiedView file
Loading diff…