From: "zverok (Victor Shepelev)" Date: 2022-10-14T13:59:24+00:00 Subject: [ruby-core:110284] [Ruby master Misc#19054] `else` in exception-handling context vs early return Issue #19054 has been reported by zverok (Victor Shepelev). ---------------------------------------- Misc #19054: `else` in exception-handling context vs early return https://bugs.ruby-lang.org/issues/19054 * Author: zverok (Victor Shepelev) * Status: Open * Priority: Normal ---------------------------------------- `else` in exception-handling context is rarely used (at least in codebase I saw), so we encountered it just recently: ```ruby def foo puts "body" return rescue => e p e else puts "else" ensure puts "ensure" end foo # prints "body", then "ensure" [1].each do puts "body" next rescue => e p e else puts "else" ensure puts "ensure" end # also prints "body" then "ensure" ``` E.g. `else` is ignored in both cases. Intuitively, I would expect that if no exception is raised in block, `else` is performed always���like `ensure` is performed always, exception or not, early return or not. I found only a very old discussion of this behavior in #4473 (it was broken accidentally on the road to 1.9.2, but then fixed back), but it doesn't explain the reason for it. Can somebody provide an insight on this decision, and whether it is justified at all?.. At least, it should be documented somewhere, [exception handling docs](https://docs.ruby-lang.org/en/master/syntax/exceptions_rdoc.html) doesn't mention this quirk. -- https://bugs.ruby-lang.org/ Unsubscribe: