How to get original exception object from inside a nested or wrapped Exception (for example an EJBException or RemoteException)

  • When you have an javax.ejb.EJBException, you can use the getCausedByException() that returns a java.lang.Exception.
  • A java.rmi.RemoteException there is a public field called detail of type java.lang.Throwable
  • With a java.sql.SQLException you need to use the method getNextException() to get the chained java.sql.SQLException.
  • When you have an java.lang.reflect.InvocationtargetException, you can get the thrown target java.lang.Throwable using the getTargetException() method.
As usual, the best way to check how to get that piece of information is to read the documentation of the specific Exception.

No comments:

Post a Comment

Please Provide your feedback here