Identify and apply robust Java exception handling practices to improve error clarity, security, debuggability, and system reliability.
Prerequisites: Run ./mvnw compile or mvn compile before applying any changes. If compilation fails, stop immediately — do not proceed until the project is in a valid state.
Core areas: Specific exception types instead of generic Exception/RuntimeException, try-with-resources for automatic resource cleanup, secure exception messages that avoid information leakage, exception chaining to preserve full error context, early input validation with IllegalArgumentException/NullPointerException, InterruptedException handling with interrupted-status restoration, @throws JavaDoc documentation,...
当您需要应用 Java 异常处理最佳实践时使用 - 包括使用特定异常类型、使用 try-with-resources 管理资源、保护异常消息、通过异常链保留错误上下文、使用快速失败原则尽早验证输入、正确处理线程中断、使用 @throws 记录异常、强制执行日志策略、在 API 边界转换异常、管理重试和幂等性、强制超时、附加抑制的异常以及在异步/响应式代码中传播故障。 java 技能项目的一部分 来源:jabrena/cursor-rules-java。