【发布时间】:2014-03-21 05:06:54
【问题描述】:
我试图在Java 中使用MySQL 捕获特定异常。但是,它运行的是 catch (SQLException ex) 而不是我想要的。
catch (MySQLIntegrityConstraintViolationException ex) {
}
catch (SQLException ex) {
}
得到以下错误,我希望它运行catch (MySQLIntegrityConstraintViolationException ex) 函数。
11:12:06 AM DAO.UserDAO createUser
SEVERE: null
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'idjaisjddiaij123ij' for key 'udid'
为什么它运行catch (SQLException ex) 而不是catch (MySQLIntegrityConstraintViolationException ex)?
【问题讨论】:
-
你能添加 ex.printStackTrace();在每个 catcha 中并粘贴异常?
-
它是否会出现在
.getCause()中?
标签: java mysql exception exception-handling error-handling