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 classes
2+
3+class AppError < RuntimeError
4+end
5+
6+class NotFoundError < AppError
7+end
8+
9+# Raise custom exception
10+begin
11+ raise NotFoundError, "item not found"
12+rescue NotFoundError => e
13+ puts e # item not found
14+rescue AppError => e
15+ puts "app error"
16+end
17+
18+# Raise with class name
19+begin
20+ raise AppError, "something went wrong"
21+rescue NotFoundError => e
22+ puts "not found"
23+rescue AppError => e
24+ puts e # something went wrong
25+end
26+
27+# Bare rescue catches all
28+begin
29+ raise "generic error"
30+rescue => e
31+ puts e # generic error
32+end
33+
34+puts "done"