marți, 3 martie 2015

[OmniFaces utilities (2.3/2.1/2.0)] Unwrap the nested causes of given exception


[OmniFaces utilities] The unwrap() method unwraps the nested causes of given exception as long as until it is not an instance of the given type and then return it. If the given exception is already not an instance of the given type, then it will directly be returned. Or if the exception, unwrapped or not, does not have a nested cause anymore, then it will be returned. This is particularly useful if you want to unwrap the real root cause out of a nested hierarchy of ServletException or FacesException.

Method:

OmniFaces 2.3 implementation (improve Exceptions#unwrap() to take varargs)

OmniFaces 2.1 implementation:

OmniFaces 2.0 implementation:
Note This is particularly useful if you want to unwrap the real root cause out of a nested hierarchy of ServletException or FacesException.

Usage:

Example 1 - this is copy-pasted from OmniFaces documentation

try{
   //...
   } catch (FacesException e) {
      Exception realRootCause = Exceptions.unwrap(e, FacesException.class);
      // ...
   }

Example 2 - unwrap ServletException

try{
   //...
   } catch (ServletException e) {
      Exception realRootCause = Exceptions.unwrap(e, ServletException.class);
      // ...
   }

Niciun comentariu:

Trimiteți un comentariu