---
title: Catch Specific Exceptions
impact: HIGH
impactDescription: prevents hiding critical system errors and unexpected behavior
tags: error-handling, maintenance, safety, quality
---

## Catch Specific Exceptions

Avoid catching the generic `Exception` or `StandardError` classes without a good reason. This can hide bugs and system-level issues like `NoMemoryError` or `SignalException`.

**Incorrect (generic rescue):**

```ruby
begin
  do_something
rescue => e # Rescues StandardError
  log_error(e)
end

begin
  do_something
rescue Exception => e # Even worse, rescues everything
  log_error(e)
end
```

**Correct (specific rescue):**

```ruby
begin
  do_something
rescue ActiveRecord::RecordNotFound => e
  handle_missing_record(e)
rescue JSON::ParserError => e
  handle_invalid_json(e)
end
```

**Tools:** RuboCop (`Style/RescueStandardError`)
---
