Project

General

Profile

Actions

Feature #15936

open

on_error in lieu of rescue, raise

Added by kylemacey (Kyle Macey) almost 5 years ago. Updated almost 5 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:93227]

Description

A common bad pattern in ruby is to rescue any exception and accidentally clobber the exception.

begin
  some_method
rescue StandardError
  # 
end

Most linters will complain if you write rescues like the code above. However, this could be useful if we want to perform an operation on any error, as long as we re-raise the exception after doing our work.

begin
  some_method
rescue StandardError
  job.fail! 
  raise
end

Here, though, we run the risk of potentially forgetting to reraise the exception, or having to make exceptions in our linter for an operation that is overall benign.

What would be a thought on using another keyword that doesn't actually rescue an exception, but performs an operation in the event of an error? Similar to ensure, but only in the event of an error.

begin
  some_method
on_error StandardError
  job.fail! 
end

(obviously, someone more creative than me should come up with a better name)

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0