如何遍历Exception getCause()以查找具有详细消息的根本原因 [英] How can I loop through Exception getCause() to find root cause with detail message

查看:875
本文介绍了如何遍历Exception getCause()以查找具有详细消息的根本原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在休眠状态下调用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

The Apache ExceptionUtils provide the following method:

Throwable getRootCause(Throwable throwable) 

以及

String getRootCauseMessage(Throwable th) 

这篇关于如何遍历Exception getCause()以查找具有详细消息的根本原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆