---
title: Avoid rescuing the Exception class
impact: HIGH
impactDescription: Prevent hiding critical system errors.
tags: ruby, errors, exception, safety
---

## Avoid rescuing the Exception class

Prevent hiding critical system errors. Never rescue the generic `Exception` class as it catches system-level errors (like `SignalException`, `NoMemoryError`, `SystemExit`). Rescue specific exception classes or `StandardError` instead.

**Incorrect (Dangerous):**

```ruby
begin
  do_something
rescue Exception => e
  logger.error(e.message)
end
```

**Correct (Safe):**

```ruby
begin
  do_something
rescue StandardError => e # Or just 'rescue => e' which defaults to StandardError
  logger.error(e.message)
end

# Or specific
rescue ActiveRecord::RecordNotFound => e
  # handle
```

**Tools:** RuboCop (`Lint/RescueException`)
