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 邊界轉換異常、管理重試和冪等性、超步響應時在 API 異常響應時在傳輸/異常響應時在傳輸/異常的情況下傳播行為。 java 技能專案的一部分 來源:jabrena/cursor-rules-java。