Aller au contenu

Broad Exception Catch (ARCH6153)

Ce contenu n’est pas encore disponible dans votre langue.

Key ruby.logging.broad-rescue · Severity info · Category logging

Catching the most general exception type (Exception, StandardError) also masks unexpected, unrelated failures. This hides real problems.

def process(order)
charge(order)
rescue Exception => e
Rails.logger.error(e.message)
end
def process(order)
charge(order)
rescue PaymentError, Net::TimeoutError => e
Rails.logger.error("Payment failed: #{order.id}", exception: e)
end

Rescue only the specific exception types you can handle; use domain exceptions instead of Exception/StandardError.