接受异常并将其转换为GrailsWrappedRuntimeException之后,renderException标记将引发错误。
Controller 代码:
def onError(Exception e) {
def ge = new GrailsWrappedRuntimeException( servletContext, e )
assert ge instanceof GrailsWrappedRuntimeException
render(view: "/error", model: [ exception: ge ])
}
error.gsp
<g:renderException exception="${exception}" />
异常(exception):
No signature of method: org.codehaus.groovy.grails.plugins.web.taglib.RenderTagLib.prettyPrintStatus() is applicable for argument types: (null) values: [null]. Stacktrace follows:
Message: Error processing GroovyPageView: Error executing tag <g:renderException>: No signature of method: org.codehaus.groovy.grails.plugins.web.taglib.RenderTagLib.prettyPrintStatus() is applicable for argument types: (null) values: [null]
最佳答案
看起来属性名称“exception”是Grails错误处理机制所特有的。在我看来,该属性名称已被grails的默认错误处理机制所覆盖。如果我在 Controller 和error.gsp中将名称更改为其他名称,例如“foo_exception”,则页面会正确显示传递给onError的异常。
关于grails - 使用Grails错误error.gsp和GrailsWrappedRuntimeException错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24678526/