我想拋出自定義異常,具體取決於什麼樣的SQLException被捕獲。是否有一個Maven倉庫,其中包含一個包含所有PostgreSQL錯誤代碼枚舉的庫?包含所有PostgreSQL錯誤代碼的枚舉的庫
E.g.
try {
doSomethingThatThrowsAnSqlException();
} catch (SQLException e) {
if (e.getSQLState().equals(PostgreSQLError.UNIQUE_VIOLATION.getCode())) {
throw new CustomException("custom message");
}
}
https://www.postgresql.org/docs/current/static/errcodes-appendix.html –
爲什麼不創建一個自定義的類與枚舉從這裏? https://www.postgresql.org/docs/9.5/static/errcodes-appendix.html – Apostolos
@Apostolos,因爲它會浪費工作,並容易出現人爲錯誤...反正它看起來像e.getErrorCode()didn不會返回我期望的結果...... –