我有一个@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
}
}
这可能吗?