【发布时间】:2016-03-29 10:43:03
【问题描述】:
我有一个@ControllerAdvice 类来处理来自我的 SpringMVC 控制器的异常。我想在 @ExceptionHandler 方法中捕获已知类型的异常 (RuntimeException),然后抛出 e.getCause() 异常并让该异常被同一个 @ControllerAdvice 类捕获。
示例代码:
@ControllerAdvice
public class ExceptionHandlingAdvice
{
@ExceptionHandler( RuntimeException.class )
private void handleRuntimeException( final RuntimeException e, final HttpServletResponse response ) throws Throwable
{
throw e.getCause(); // Can be of many types
}
// I want any Exception1 exception thrown by the above handler to be caught in this handler
@ExceptionHandler( Exception1.class )
private void handleAnException( final Exception1 e, final HttpServletResponse response ) throws Throwable
{
// handle exception
}
}
这可能吗?
【问题讨论】:
标签: java spring-mvc exceptionhandler