Skip to content
Back to skills

Raise The Narrowest Exception

ASecurity

When raising an error, choose the narrowest built-in exception that fits

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added October 17, 2026
ai-agents

Security analysis

A100/100

Scanned October 17, 2026

npx -y skills add samugit83/cortex --skill raise-the-narrowest-exception --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Raise The Narrowest Exception?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Raise The Narrowest Exception
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/samugit83-raise-the-narrowest-exception/badge)](https://www.skillsdirectory.com/skills/samugit83-raise-the-narrowest-exception)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: raise-the-narrowest-exception
description: When raising an error, choose the narrowest built-in exception that fits
---

# Exceptions

A bare `Exception` tells a caller nothing it can act on.

- A bad argument is a `ValueError`; a bad argument *type* is a `TypeError`.
- A missing key is a `KeyError`, a missing attribute an `AttributeError`.
- Define your own class only when a caller would plausibly catch it on its own,
  and then give it a base from the same module so the whole family is catchable.

Put the offending value in the message: `f"not a rate: {text!r}"` beats
"invalid input", and `!r` keeps the quotes that show where the whitespace was.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.