error-handling

Implements exception hierarchies, error propagation, and recovery patterns in Python code.

Updated Sep 2, 2026
One-click install
npx skills add https://github.com/Dazlarus/karl-code --skill error-handling-dazlarus
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: error-handling
Source: https://github.com/Dazlarus/karl-code/tree/main/.agents/skills/error-handling
Command: npx skills add https://github.com/Dazlarus/karl-code --skill error-handling-dazlarus

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Codebases often suffer from bare except clauses, swallowed exceptions, missing context in error messages, and deeply nested try-except blocks that make failures hard to diagnose and debug. ## Core Features & Use Cases - Exception Hierarchy Design: Guides creation of domain-specific exception classes with rich context attributes and structured error responses. - Error Handling Review: Detects anti-patterns such as bare except clauses, missing exception chaining, and nested try-except blocks, then suggests concrete fixes. - Use Case: When writing a new module that calls external tools or APIs, apply this Skill to define proper exception classes, use context managers for resources, and handle async errors with asyncio.gather and return_exceptions. ## Quick Start Review the error handling in my Python module and fix any bare except clauses, missing exception chaining, and nested try-except blocks.

Frequently Asked Questions about error-handling

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

FAQPage Schema
How do I create custom exception classes in Python?▼

Define a base exception inheriting from Exception, then create category and specific subclasses. Add context attributes like tool_name or exit_code in __init__ and override __str__ to include actionable debugging details.

How to handle exceptions in async Python code with asyncio?▼

Use asyncio.gather with return_exceptions=True to collect all results and exceptions without losing failures. Alternatively use asyncio.wait with ALL_COMPLETED and inspect each task's exception for logging.

Why should I avoid bare except clauses in Python?▼

Bare except catches everything including system exits and keyboard interrupts, hiding real bugs. Catch specific expected exceptions instead, and only catch broad Exception at top-level error boundaries with logging and re-raising.

What is exception chaining with raise from in Python?▼

Exception chaining uses 'raise NewError(...) from e' to preserve the original traceback when converting exceptions. This keeps root-cause information visible in logs instead of losing the underlying error context.

When should I use context managers for resource cleanup?▼

Use context managers whenever a resource needs guaranteed cleanup, such as files, database connections, or network sockets. The with statement ensures __exit__ runs even when exceptions occur, preventing resource leaks.