Actions
Bug #20026
closedRuby doesn't throw a syntax error when rescuing with ||
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin23]
Description
We had a coworker new to ruby try an interesting syntax for rescue that doesn't result in a syntax error, and works partially.
Why does ruby allow the logical OR || operator, is there a purpose for this? If not this feels like it should be a syntax error, instead of resulting in partially working code.
class FooError < StandardError; end
class BarError < StandardError; end
# works
begin
raise FooError
rescue FooError || BarError => e
puts "rescued #{e.class}"
end
# doesn't work
begin
raise FooError
rescue FooError || BarError => e
puts "rescued #{e.class}"
end
Actions
Like0
Like1Like0Like1