---
title: Avoid empty catch blocks
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > Avoid empty catch blocks
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Avoid empty catch blocks

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com, us2.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ({% placeholder "user-datadog-site-name" /%}).
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**ID:** `dart-code-quality/empty-catches`

**Language:** Dart

**Severity:** Warning

**Category:** Code Style

## Description{% #description %}

When a catch block has no code, errors are swallowed and nothing shows up in logs or stack traces. That makes real bugs very hard to fix.

If you need to ignore an error on purpose, say so explicitly: log the exception, or add a short comment in the catch block explaining why it is safe to skip. A completely empty catch block should be avoided.

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```dart
void main() {
  try {
    risky();
  } catch (e) {}

  try {
    risky();
  } on Exception catch (e, s) {}

  try {
    risky();
  } catch (e) {
    
  }
}

void risky() {}
```

## Compliant Code Examples{% #compliant-code-examples %}

```dart
import 'dart:io';

void main() {
  try {
    risky();
  } catch (e) {
    print(e);
  }

  try {
    risky();
  } on IOException catch (e) {
    print(e);
  }

  try {
    risky();
  } catch (e) {
    // Intentionally ignored: cleanup is best-effort.
  }

  try {
    risky();
  } catch (_) {}
}
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}
 