How can I loop through Exception getCause() to find root cause with detail message

exception, java, plsql

Solution

The Apache ExceptionUtils provide the following method:

Throwable getRootCause(Throwable throwable) 

as well as

String getRootCauseMessage(Throwable th) 

Problem

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. 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. 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.) Thanks.

Original source

Related problems