python-error-handling

Audit Python exception hierarchies and enforce narrow catching with raise from.

1|1|Updated Apr 6, 2026
One-click install
npx skills add https://github.com/Jylhis/skills --skill python-error-handling-jylhis
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-error-handling
Source: https://github.com/Jylhis/skills/tree/main/skills/python-error-handling
Command: npx skills add https://github.com/Jylhis/skills --skill python-error-handling-jylhis

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Python error handling: exception hierarchies, try/except audit, custom exceptions, contextlib, exception chaining, ExceptionGroup. Apply when reviewing error paths or designing an exception API.

Core Features & Use Cases

  • Analyze exception hierarchies and re-raise with context to preserve debugging information.
  • Audit try/except blocks to enforce minimal catch and proper re-raise strategies.
  • Define and implement custom exceptions with structured data for better API design.
  • Apply modern features like contextlib and ExceptionGroup to improve resilience.

Quick Start

Propose a minimal, well-structured exception strategy for a given Python module and show how to use narrow catches and context propagation.

Frequently Asked Questions about python-error-handling

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I audit try/except blocks to enforce minimal exception catching in Python?

To audit try/except blocks for minimal exception catching in Python, you review error paths to enforce narrow catches and proper re-raise strategies. This preserves debugging information and ensures robust API error handling.

What is the best way to preserve Python tracebacks when re-raising exceptions?

The best way to preserve Python tracebacks when re-raising exceptions is using raise from for exception chaining. This maintains the original context and debugging information across your error paths.

How do I define custom Python exceptions with structured data for API design?

You define custom Python exceptions with structured data by implementing exception hierarchies that carry specific attributes. This documents API surfaces clearly and provides better error context for library consumers.

When should I use ExceptionGroup and contextlib for Python error handling?

Use ExceptionGroup and contextlib for Python error handling when you need to manage multiple raised exceptions simultaneously or utilize context managers for resource cleanup. These modern features improve service resilience.

Does this Python exception handling approach work for libraries and APIs?

Yes, this Python exception handling approach works across libraries, services, and APIs. It guides reviews of exception hierarchies and API surfaces to ensure robust error propagation and structured custom exceptions.

Why does broad exception catching cause problems in Python services?

Broad exception catching in Python services causes problems by hiding specific errors and losing original traceback context. Enforcing narrow exception catches with proper re-raise strategies prevents silent failures and preserves debugging information.