---
title: "Never swallow errors · Agent Wranglers"
url: https://agentwranglers.se/playbook/architecture/errors-and-nulls/never-swallow-errors
updated: 2026-10-20
licence: "All rights reserved"
---

# Never swallow errors

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Errors and nulls](https://agentwranglers.se/playbook/architecture/errors-and-nulls)
- Rule: Never catch an error and carry on as if nothing happened. Handle it, add context and rethrow it, or let it reach the edge.
- How: Catch only errors you can do something about. When you rethrow, keep the original as the cause. Log once, at the edge, with a reference the user can quote.
- Check: A linter flags empty catch blocks and broad catches. Examples are ESLint's `no-empty`, Ruff's `BLE001` and `S110`, and PHP_CodeSniffer's `Generic.CodeAnalysis.EmptyStatement`.

Example:

```ts
// Bad: the order is lost and nobody knows
try { await saveOrder(order); } catch {}

// Good: add context and keep the cause
try {
  await saveOrder(order);
} catch (error) {
  throw new OrderNotSaved(order.id, { cause: error });
}
```

```python
try:
    save_order(order)
except DatabaseError as error:
    raise OrderNotSaved(order.id) from error
```

```java
try {
    saveOrder(order);
} catch (SQLException e) {
    throw new OrderNotSaved(order.id(), e);
}
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers architecture playbook: https://agentwranglers.se/playbook/architecture/errors-and-nulls/never-swallow-errors`.

- Previous: [Make fields required unless absence is valid](https://agentwranglers.se/playbook/architecture/errors-and-nulls/required-fields)
- Next: [Release every resource you open](https://agentwranglers.se/playbook/architecture/errors-and-nulls/release-resources)
- [Errors and nulls](https://agentwranglers.se/playbook/architecture/errors-and-nulls)
