AgentSkillsCN

Global Error Handling

实现健壮的错误处理,提供友好用户消息、快速失败验证、特定异常类型与恰当资源清理,贯穿整个应用。当编写try-catch块、抛出或捕获异常、实现错误边界、处理API错误,或管理代码库任何部分的错误状态时,使用此技能。在早期验证输入(快速失败)、向用户提供清晰可操作的错误消息而不暴露安全细节、使用特定异常类型而非通用错误、在恰当边界实现集中式错误处理、设计优雅降级、实现指数退避重试逻辑,或确保finally块中资源被清理时,应用此技能。此技能确保错误被恰当捕获与处理,即使发生错误用户体验依然积极,安全得到保障不泄露敏感信息,系统在非关键服务失败时继续运行或优雅降级。

SKILL.md
--- frontmatter
name: Global Error Handling
description: Implement robust error handling with user-friendly messages, fail-fast validation, specific exception types, and proper resource cleanup across the application. Use this skill when writing try-catch blocks, throwing or catching exceptions, implementing error boundaries, handling API errors, or managing error states in any part of the codebase. Apply this skill when validating inputs early (fail fast), providing clear actionable error messages to users without exposing security details, using specific exception types rather than generic errors, implementing centralized error handling at appropriate boundaries, designing for graceful degradation, implementing retry logic with exponential backoff, or ensuring resources are cleaned up in finally blocks. This skill ensures errors are caught and handled appropriately, user experience remains positive even when errors occur, security is maintained by not leaking sensitive information, and systems continue operating or degrade gracefully when non-critical services fail.

Global Error Handling

This Skill provides Claude Code with specific guidance on how to adhere to coding standards as they relate to how it should handle global error handling.

When to use this skill

  • When writing try-catch-finally blocks or exception handling logic
  • When throwing custom errors or exceptions with meaningful messages
  • When validating inputs and failing fast on invalid data
  • When implementing error boundaries in React or error handling middleware
  • When handling API errors, network failures, or external service calls
  • When providing user-facing error messages that are clear and actionable
  • When logging errors with appropriate context (stack traces, user actions, timestamps)
  • When implementing retry strategies with exponential backoff for transient failures
  • When ensuring resource cleanup (file handles, database connections, network sockets)
  • When centralizing error handling at API controllers, service boundaries, or UI error boundaries
  • When designing systems to degrade gracefully when non-critical services fail
  • When avoiding exposing sensitive information (stack traces, internal paths) to end users
  • When using specific exception types (ValidationError, NotFoundError) instead of generic ones
  • When implementing proper error propagation without swallowing errors silently

Instructions

For details, refer to the information provided in this file: global error handling