while (cause instanceof InvocationTargetException) {
cause = ((InvocationTargetException) cause).getTargetException();
}
//
Module errorHandlerModule = module;
ControllerErrorHandler errorHandler = errorHandlerModule.getErrorHandler();
while (errorHandler == null && errorHandlerModule != null) {
errorHandlerModule = errorHandlerModule.getParent();
if (errorHandlerModule != null) {
errorHandler = errorHandlerModule.getErrorHandler();
if (errorHandler != null) {
if (errorHandler.getClass().isAnnotationPresent(NotForSubModules.class)) {
errorHandler = null;
continue;
}
}
} else {
errorHandler = null;
break;
}
}
Object instruction = null;
if (errorHandler != null) {
if (logger.isDebugEnabled()) {
logger.debug("exception happended; " + errorHandler.getClass().getName()
+ " will handle the exception: " //
+ cause.getClass().getName() + ":" + cause.getMessage());
}
rose.getInvocation().setViewModule(errorHandlerModule);
//
HttpServletRequest request = rose.getInvocation().getRequest();
WebUtils.exposeErrorRequestAttributes(request, cause, null);
StackTraceSimplifier.simplify(cause); //对栈进行简化
instruction = errorHandler.onError(rose.getInvocation(), cause);
}
// onError方法返回null,表示需要重新throw出去
// rethrow出去的不是cause而是invException,目的要把整个异常抛出来,以让知道整个异常的来由
if ((errorHandler == null) || (instruction == null)) {