Skip to content

Commit 5267c97

Browse files
committed
Avoid Kernel.suppress(Exception)
ref: rubocop/rubocop-rails#1547 Using `Kernel.suppress(Exception) { ?? }` is effectively equivalent to: ```ruby begin ?? rescue Exception end ``` Since rescuing `Exception` directly is discouraged by `Lint/RescueException`, it makes sense to discourage this usage as well.
1 parent 86bffd4 commit 5267c97

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.adoc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,27 @@ datetime.to_fs(:db)
17681768
42.to_fs(:human)
17691769
----
17701770

1771+
=== Do not rescue `Exception` via `Kernel.suppress` [[kernel-suppress-exception]
1772+
1773+
Using `Kernel.suppress(Exception)` is effectively equivalent to rescuing `Exception`, which is discouraged.
1774+
1775+
[source,ruby]
1776+
----
1777+
# bad
1778+
suppress(Exception) do
1779+
do_something
1780+
end
1781+
1782+
# good
1783+
begin
1784+
do_something
1785+
rescue Exception => e
1786+
process_exception(e)
1787+
1788+
raise
1789+
end
1790+
----
1791+
17711792
== Time
17721793

17731794
=== Time Zone Config [[tz-config]]

0 commit comments

Comments
 (0)