为什么Grails剥夺了我的异常?

Tob*_*bia 7 error-handling grails groovy exception

如果你把它放在一个控制器动作中:

def inner = new RuntimeException("inner")
def middle = new Exception("middle", inner)
def outer = new IllegalArgumentException("outer", middle)
throw outer
Run Code Online (Sandbox Code Playgroud)

Grails的错误调试页面(最重要的是,日志)只显示内部异常类及其消息:

错误500:内部服务器错误

URI:/...
类: java.lang.RuntimeException
消息:内部

这是有问题的,因为当您选择使用更具描述性的消息来包装异常时,大多数情况下,外部消息在调试问题时更为重要.

实际上,在原因链中包含所有异常,包括类名,消息和堆栈跟踪,就像常规Java一样.

我已经尝试在错误页面中自己打印异常,但是在调用错误视图之前发生了剥离.

是否有可以改变此行为的配置参数?

编辑:我发布了一个错误,启动了一个邮件列表线程,但到目前为止,我还没有找到一个解决方法,甚至还没有发现这种剥离的Grails源代码中的位置.

Tob*_*bia 0

我找到了删除异常的地方。

它在org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver.resolveException()其中调用以下方法:

protected Exception findWrappedException(Exception e) {
    if ((e instanceof InvokerInvocationException)||(e instanceof GrailsMVCException)) {
        Throwable t = getRootCause(e);
        if (t instanceof Exception) {
            e = (Exception) t;
        }
    }
    return e;
}
Run Code Online (Sandbox Code Playgroud)

这会测试当前异常是否是 InvokerInitationException 或 GrailsMVCException(这是由控制器内的用户代码引发的情况),然后通过抛出所有外部异常getRootCause()

这显然是一个错误。

我还发现原来的异常可以在request."javax.servlet.error.exception"