Exception: LocalJumpError

Inherits:
StandardError show all
Defined in:
proc.c,
proc.c

Overview

Raised when Ruby can’t yield as requested.

A typical scenario is attempting to yield when no block is given:

def call_block
  yield 42
end
call_block

raises the exception:

LocalJumpError: no block given (yield)

A more subtle example:

def get_me_a_return
  Proc.new { return 42 }
end
get_me_a_return.call

raises the exception:

LocalJumpError: unexpected return

Instance Method Summary collapse

Methods inherited from Exception

#==, #backtrace, #backtrace_locations, #cause, #exception, exception, #full_message, #initialize, #inspect, #message, #set_backtrace, #to_s, to_tty?

Constructor Details

This class inherits a constructor from Exception

Instance Method Details

#exit_valueObject

Returns the exit value associated with this LocalJumpError.

Returns:



3054
3055
3056
3057
3058
# File 'proc.c', line 3054

static VALUE
localjump_xvalue(VALUE exc)
{
    return rb_iv_get(exc, "@exit_value");
}

#reasonObject

The reason this block was terminated: :break, :redo, :retry, :next, :return, or :noreason.



3068
3069
3070
3071
3072
# File 'proc.c', line 3068

static VALUE
localjump_reason(VALUE exc)
{
    return rb_iv_get(exc, "@reason");
}