# Decide Guard Vs Exception

> When to return early vs throw. Control flow clarity.

- Skill: `attac-t/decide-guard-vs-exception` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add attac-t/decide-guard-vs-exception`
- Raw SKILL.md: https://api.skillmd.com/api/skills/attac-t/decide-guard-vs-exception/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: attac-t (https://skillmd.com/u/attac-t)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/attac-t/decide-guard-vs-exception

---


# Skill: Guard vs Exception

> "Guards return. Exceptions signal failure."

## The Decision

**Return early when:**
- Nothing to do is acceptable (empty collection, already processed)
- Caller can continue normally with the return value
- It's a business rule, not an error

**Throw exception when:**
- Caller must handle the failure
- Invalid state that shouldn't exist
- Programmer error (null where null shouldn't be)

## The Heuristic

Ask: *"Can the caller proceed normally with a return value?"*
- **Yes** → Return (Result object, empty collection, early exit)
- **No** → Throw (caller must handle or propagate)

## The Quick Test

| Scenario                    | Answer  | Use       |
|-----------------------------|---------|-----------|
| Empty input, nothing to do? | Ok      | Return    |
| Already processed?          | Ok      | Return    |
| Rate limited, retry later?  | Maybe   | Return Result |
| Missing required data?      | Not ok  | Throw     |
| Unauthorized access?        | Not ok  | Throw     |
| Invalid state (bug)?        | Not ok  | Throw     |

## Real-World Examples

See [examples.md](examples.md).

