如何循环遍历 Exception getCause() 以找到带有详细消息的根本原因 [英] How can I loop through Exception getCause() to find root cause with detail message
问题描述
我试图在休眠状态下调用 saveOrUpdate()
来保存数据.由于列具有唯一索引,因此当我通过 Eclipse 调试器查看时,它会抛出 ConstraintViolationException
.
I am trying to call saveOrUpdate()
in hibernate to save data. Since columns have unique index, so its throws ConstraintViolationException
when I look through via Eclipse debugger.
因为在向表中插入数据时,不同的异常的根本原因可能不同.
我想知道,如何循环/遍历 getCause()
以检查异常及其消息的根本原因是什么.
Since root cause could be different for different exception while inserting data to table.
I wanted to know, how can I loop / traverse through getCause()
to check what is the root cause of exception and its message.
更新:
感谢大家的友好回应,我想要的输出如下图所示:
我需要访问 detailMessage 字段.
(如果不能让我的问题更清楚,我真的很抱歉.)
Update:
Thanks everyone for your kind response, thing is I want output like in below image:
I need to access detailMessage field.
(I am really sorry If could not make my question more clear.)
谢谢.
推荐答案
Apache ExceptionUtils 提供如下方法:
The Apache ExceptionUtils provide the following method:
Throwable getRootCause(Throwable throwable)
以及
String getRootCauseMessage(Throwable th)
这篇关于如何循环遍历 Exception getCause() 以找到带有详细消息的根本原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!