从SQLException异常中获取SQLState



我有代码抛出SQLException包装在RuntimeException,如:

} catch (RuntimeException e) {
Throwable t = e.getCause();

while ((t != null) && !(t instanceof java.sql.SQLException)) {
t = t.getCause();
}
. . . Someother code
if (SQLState==) {
//throw new custom exception based on  SQLState);
}

如何在if循环中获得SQLState ?在while循环之外,t为空。

得到答案了

} catch (RuntimeException e) {
Throwable t = e.getCause();
SQLException exp;
while ((t != null) && !(t instanceof SQLException)) {
t = t.getCause();
exp= (SQLException) t;  
}
if (exp.getSQLState=="....")) {
throw new custom exception based on  SQLState); 
}
}

相关内容

  • 没有找到相关文章

最新更新