它包裹在一个中
EJBTransactionRolledbackException,因此您应该尝试抓住那个而不是
ConstraintViolationException。
在
ConstraintViolationException首先由包裹
PersistenceException,然后通过
RollbackException,最后通过
EJBTransactionRolledbackException。
getCause()在
Exception遇到约束违例之前,应调用的方法,否则应为null,这表示异常不是由于约束违例引起的。您可以尝试如下 *** 作:
try { memberDao.create(newMember);} catch (EJBTransactionRolledbackException e) { Throwable t = e.getCause(); while ((t != null) && !(t instanceof ConstraintViolationException)) { t = t.getCause(); } if (t instanceof ConstraintViolationException) { // Here you're sure you have a ConstraintViolationException, you can handle it }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)