Example usage for org.springframework.util ReflectionUtils rethrowException

List of usage examples for org.springframework.util ReflectionUtils rethrowException

Introduction

In this page you can find the example usage for org.springframework.util ReflectionUtils rethrowException.

Prototype

public static void rethrowException(Throwable ex) throws Exception 

Source Link

Document

Rethrow the given Throwable exception , which is presumably the target exception of an InvocationTargetException .

Usage

From source file:org.springframework.web.servlet.mvc.multiaction.MultiActionController.java

/**
 * We've encountered an exception thrown from a handler method.
 * Invoke an appropriate exception handler method, if any.
 * @param request current HTTP request/*  w  w  w.j ava 2  s  . c  o m*/
 * @param response current HTTP response
 * @param ex the exception that got thrown
 * @return a ModelAndView to render the response
 */
private ModelAndView handleException(HttpServletRequest request, HttpServletResponse response, Throwable ex)
        throws Exception {

    Method handler = getExceptionHandler(ex);
    if (handler != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Invoking exception handler [" + handler + "] for exception: " + ex);
        }
        try {
            Object returnValue = handler.invoke(this.delegate, request, response, ex);
            return massageReturnValueIfNecessary(returnValue);
        } catch (InvocationTargetException ex2) {
            logger.error("Original exception overridden by exception handling failure", ex);
            ReflectionUtils.rethrowException(ex2.getTargetException());
        } catch (Exception ex2) {
            logger.error("Failed to invoke exception handler method", ex2);
        }
    } else {
        // If we get here, there was no custom handler or we couldn't invoke it.
        ReflectionUtils.rethrowException(ex);
    }
    throw new IllegalStateException("Should never get here");
}