无法捕获ConstraintViolationException

无法捕获ConstraintViolationException,第1张

无法捕获ConstraintViolationException

包裹在一个中

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    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5442702.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存