Bare rescue
clauses without specifying an exception class catch all StandardError exceptions. This creates several problems:
Hidden bugs: Unexpected errors get silently caught and handled the same way as expected ones. A typo in your code might raise a
NameError, but your bare rescue will catch it and treat it like a normal business exception.
Difficult debugging: When something goes wrong, you won’t know what actually failed. The original error gets masked by generic
error handling.
Unclear intent: Other developers (including future you) can’t tell what exceptions you intended to handle. This makes the code
harder to maintain and modify safely.
Ruby’s exception hierarchy means that rescue
without a class catches StandardError and all its subclasses. This includes common
exceptions like ArgumentError, NoMethodError, and RuntimeError that usually indicate programming mistakes rather than expected conditions.
Being explicit about which exceptions to catch makes your code more robust and easier to debug.
What is the potential impact?
Bare rescue clauses can hide critical bugs and make applications harder to debug and maintain. Unexpected errors may be silently swallowed, leading
to incorrect application behavior that’s difficult to trace and fix.