Project

General

Profile

Actions

Bug #4473

closed

Calling return within begin still executes else

Added by thuss (Todd Huss) about 13 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
ruby -v:
-
Backport:
[ruby-core:<unknown>]

Description

=begin
I see this issue in 1.9.2-p0 through the current version 1.9.2-p136 on Mac OS X. The following code prints 'else executed'. Whereas in Ruby 1.8.x it would not execute the else statement if you called return from within a begin block.

In summary, I would expect the following code to not print anything, but in Ruby 1.9.2 it actually prints 'else executed':

This code prints 'else executed'

def test_return_in_method
begin
return
rescue
puts 'rescue executed'
else
puts 'else executed'
end
end
test_return_in_method
=end


Files

ruby-1.9.2-return-else.rb (167 Bytes) ruby-1.9.2-return-else.rb thuss (Todd Huss), 03/06/2011 04:40 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0