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.
Incorrect
Section titled “Incorrect”def process(order) charge(order)rescue Exception => e Rails.logger.error(e.message)endCorrect
Section titled “Correct”def process(order) charge(order)rescue PaymentError, Net::TimeoutError => e Rails.logger.error("Payment failed: #{order.id}", exception: e)endRescue only the specific exception types you can handle; use domain exceptions instead of Exception/StandardError.