global-error-handling

mshafei721 的头像作者 mshafei721

通过用户友好的消息、特定的异常类型、集中处理和优雅的降级来实现强大的错误处理。添加 try-catch 块、错误边界或异常处理时请使用此技能。创建自定义错误类型或异常类时。当决定在哪里处理错误时(控制器与服务层)。编写面向用户的错误消息时。使用指数退避实现重试逻辑时。当确保资源在finally块或等效模式中被清理时。

📖 中文导读:通过用户友好的消息、特定的异常类型、集中处理和优雅的降级来实现强大的错误处理。添加 try-catch 块、错误边界或异常处理时请使用此技能。创建自定义错误类型或异常类时。当决定在哪里处理错误时(控制器与服务层)。编写面向用户的错误消息时。使用指数退避实现重试逻辑时。当确保资源在finally块或等效模式中被清理时。 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。

name: Global Error Handling description: Implement robust error handling with user-friendly messages, specific exception types, centralized handling, and graceful degradation. Use this skill when adding try-catch blocks, error boundaries, or exception handling. When creating custom error types or exception classes. When deciding where to handle errors (controller vs. service layer). When writing user-facing error messages. When implementing retry logic with exponential backoff. When ensuring resources are cleaned up in finally blocks or equivalent patterns.

When to use this skill:

  • When adding try-catch blocks or error handling code
  • When creating custom error or exception classes
  • When deciding where to catch and handle errors
  • When writing error messages that users will see
  • When implementing centralized error handling at API boundaries
  • When designing systems to degrade gracefully on failure
  • When implementing retry strategies for external service calls
  • When using exponential backoff for transient failures
  • When ensuring resources (connections, file handles) are cleaned up
  • When validating inputs and failing fast with clear messages
  • When choosing between specific and generic exception types
  • When reviewing code for proper error handling patterns

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.

Instructions

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