Class: Nydp::Builtin::HandleError::CatchError

Inherits:
Object
  • Object
show all
Includes:
Helper, VM::HandleError
Defined in:
lib/nydp/builtin/handle_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#cons, #list, #literal?, #pair?, #sig, #sym, #sym?

Methods included from Converter

#n2r, #r2n

Constructor Details

#initialize(handler, vm_arg_array_size) ⇒ CatchError

Returns a new instance of CatchError.



11
12
13
# File 'lib/nydp/builtin/handle_error.rb', line 11

def initialize handler, vm_arg_array_size
  @handler, @vm_arg_array_size = handler, vm_arg_array_size
end

Instance Attribute Details

#handlerObject (readonly)

Returns the value of attribute handler.



9
10
11
# File 'lib/nydp/builtin/handle_error.rb', line 9

def handler
  @handler
end

#vm_arg_array_sizeObject (readonly)

Returns the value of attribute vm_arg_array_size.



9
10
11
# File 'lib/nydp/builtin/handle_error.rb', line 9

def vm_arg_array_size
  @vm_arg_array_size
end

Instance Method Details

#execute(vm) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/nydp/builtin/handle_error.rb', line 15

def execute vm
  e = vm.last_error = vm.unhandled_error
  vm.unhandled_error = nil
  return unless e

  vm.args = vm.args[0...vm_arg_array_size]

  msgs = []
  while e
    msgs << e.message
    e = e.cause
  end

  handler.invoke_2 vm, r2n(msgs)
end

#to_sObject



31
32
33
# File 'lib/nydp/builtin/handle_error.rb', line 31

def to_s
  "(on-err: #{handler})"
end