Skip to content

$! gets unset by rescue, even when the rescue doesn't catch the error #3237

@iconara

Description

@iconara

This code will print "#<RuntimeError: bork>" in JRuby 1.7.x as well as all MRI versions I tested, but "nil" in JRuby 9.0.0.0:

begin
  begin
    raise 'bork'
  rescue TypeError
  end
ensure
  p $!
end

Removing the inner begin … rescue makes it print "#<RuntimeError: bork>" again. It looks like rescue clears $!. The error matched by the inner rescue doesn't matter, and catching the error and re-raising it also leaves $! unset.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions