private void throwUndeclaredExceptionCause ( Throwable undeclaredException ) throws Exception { Throwable cause = undeclaredException . getCause ( ) ; if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) Tr . debug ( tc , "proceed unwrappering " + undeclaredException . getClass ( ) . getSimpleName ( ) + " : " + cause , cause ) ; // CDI interceptors tend to result in a UndeclaredThrowableException wrapped in an InvocationTargetException if ( cause instanceof UndeclaredThrowableException ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) Tr . debug ( tc , "proceed unwrappering " + cause . getClass ( ) . getSimpleName ( ) + " : " + cause , cause . getCause ( ) ) ; cause = cause . getCause ( ) ; } if ( cause instanceof RuntimeException ) { // Let the mapping strategy handle this unchecked exception. throw ( RuntimeException ) cause ; } else if ( cause instanceof Error ) { // Let the mapping strategy handle this unchecked exception. throw ( Error ) cause ; } else { // Probably an application exception occurred, so just throw it. The mapping // strategy will handle if it turns out not to be an application exception. throw ( Exception ) cause ; } }
Since some interceptor methods cannot throw Exception but the target method on the bean can throw application exceptions this method may be used to unwrap the application exception from either an InvocationTargetException or UndeclaredThrowableException .