error-handling
Establishes best practices for handling errors without system crashes or information leaks.
Install
mkdir -p .claude/skills/error-handling-yisuescopeta && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/15617" && unzip -o skill.zip -d .claude/skills/error-handling-yisuescopeta && rm skill.zipInstalls to .claude/skills/error-handling-yisuescopeta
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Implement robust error handling patterns. Enforces best practices for catching, logging, and responding to errors in a way that preserves system stability and aids debugging.Key capabilities
- →Validate inputs at system boundaries
- →Catch specific exception types
- →Create domain-specific custom exceptions
- →Log errors with contextual information
- →Sanitize user-facing error messages
- →Ensure resource cleanup using `finally` blocks
How it works
This skill implements error handling by enforcing specific exception catching, contextual logging, sanitizing user-facing messages, and ensuring resource cleanup, adhering to principles like 'fail fast'.
Inputs & outputs
When to use error-handling
- →Implement error logging
- →Handle exceptions safely
- →Sanitize user-facing errors
- →Add finally blocks
About this skill
Error Handling Patterns
Overview
Errors are inevitable. How you handle them defines the reliability of your software.
Core Principles
1. Fail Fast, Fail Loudly (in Development)
- Don't Swallow Errors: Never use empty
catchblocks. - Validate Early: Check inputs at the boundary of your system (API endpoints, public methods).
2. Specific Exceptions
- Catch Specific Types: Don't just catch
ExceptionorError. CatchFileNotFoundException,ValidationException, etc. - Custom Exceptions: Create domain-specific exceptions (e.g.,
InsufficientFundsException) to handle business logic failures distinctly from system crashes.
3. Contextual Logging
- Log the "Why": Don't just log "Error happened." Log "Failed to process payment for user X because Y."
- Include Stack Traces: Always preserve the stack trace when re-throwing or logging (but define a boundary where they are sanitized for the user).
4. User-Facing vs. System Errors
- Sanitize: Never show raw stack traces or database errors to the end-user.
- User Messages: Show helpful messages ("Something went wrong, please try again") with a correlation ID for support.
5. Cleanup
- Finally: Use
finallyblocks (or language equivalents likedeferorusing) to ensure resources (files, connections) are closed even if an error occurs.
Code Patterns
The "Result" Pattern (Functional)
Instead of throwing exceptions for expected failures, return a Result type:
type Result<T, E> = { ok: true, value: T } | { ok: false, error: E };
The "Guard Clause" Pattern
Fail fast at the top of the function to avoid nesting.
function process(data) {
if (!data) throw new Error("Data required");
if (!data.isValid) throw new Error("Invalid data");
// ... actual logic
}
Global Error Handler
Ensure every application (Web, CLI) has a top-level catch-all handler to log unhandled crashes and exit gracefully.
When not to use it
- →When using empty `catch` blocks that swallow errors
- →When showing raw stack traces or database errors to end-users
- →When logging errors without sufficient context or stack traces
Limitations
- →Errors should not be swallowed by empty catch blocks
- →Raw stack traces or database errors should not be shown to end-users
- →Stack traces should always be preserved when re-throwing or logging
How it compares
This approach systematically applies best practices for error handling, distinguishing between user-facing and system errors and promoting specific exception types, which is more reliable than generic error catching.
Compared to similar skills
error-handling side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| error-handling (this skill) | 0 | 4mo | No flags | Intermediate |
| python-testing-patterns | 77 | 2mo | Review | Intermediate |
| error-handling-patterns | 35 | 2mo | No flags | Intermediate |
| codex-claude-loop | 13 | 9mo | Review | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by Yisuescopeta
View all by Yisuescopeta →You might also like
python-testing-patterns
wshobson
Implement comprehensive testing strategies with pytest, fixtures, mocking, and test-driven development. Use when writing Python tests, setting up test suites, or implementing testing best practices.
error-handling-patterns
wshobson
Master error handling patterns across languages including exceptions, Result types, error propagation, and graceful degradation to build resilient applications. Use when implementing error handling, designing APIs, or improving application reliability.
codex-claude-loop
bear2u
Orchestrates a dual-AI engineering loop where Claude Code plans and implements, while Codex validates and reviews, with continuous feedback for optimal code quality
serena
massgen
This skill provides symbol-level code understanding and navigation using Language Server Protocol (LSP). Enables IDE-like capabilities for finding symbols, tracking references, and making precise code edits at the symbol level.
javascript-mastery
davila7
Comprehensive JavaScript reference covering 33+ essential concepts every developer should know. From fundamentals like primitives and closures to advanced patterns like async/await and functional programming. Use when explaining JS concepts, debugging JavaScript issues, or teaching JavaScript fundamentals.
find-bugs
davila7
Find bugs, security vulnerabilities, and code quality issues in local branch changes. Use when asked to review changes, find bugs, security review, or audit code on the current branch.