Java – find the first cause of an exception

In the interests of not reinventing the wheel, if you’re using Apache Commons Lang, then look at ExceptionUtils.getRootCause().

Is it worth including a library just for that? Maybe not. But if you already have it on your classpath, it’s there for you, and note that it does some things that a ‘naive’ implementation might not do (e.g. deal with cycles in the cause chain… ugh!)

Leave a Comment