4 # Emulates the interface of Exception, but isn't one.
7 def initialize(name, value, ctx)
17 "A thrown value from Kernel#throw"
21 if @context.kind_of? MethodContext
22 @context = Backtrace.backtrace(@context)
28 def set_backtrace(obj)
36 def self.register(sym)
37 cur = Thread.current[:__catches__]
40 Thread.current[:__catches__] = cur
52 def self.available?(sym)
53 cur = Thread.current[:__catches__]
54 return false if cur.nil?
62 ThrownValue.register(sym) do
65 rescue ThrownValue => val
66 return val.value if val.name == sym
67 Rubinius.asm(val) do |v|
73 module_function :catch
75 def throw(sym, value = nil)
76 unless ThrownValue.available? sym
77 raise NameError.new("uncaught throw `#{sym}'", sym.to_sym)
80 exc = ThrownValue.new(sym, value, MethodContext.current.sender)
81 Rubinius.asm(exc) do |v|
86 module_function :throw