Grails error handler always receives null pointer

让人想犯罪 __ 提交于 2019-12-23 17:40:24

问题


We have a custom error controller that gets called after all of our errors. However, most of our errors that get thrown end up coming into the controller as null pointers, even though the original error was not a null pointer. Any ideas? Code below. Bootstrap and UrlMappings available if needed. Thanks

Error Handler method

def HandleErrors =
{

    def exception = request.exception.cause.class  

    if (exception) 
    { 
        Exception ex = request.exception  //This exception is always a NPE
            ...

Block of code throwing the exception. I originally did not have a try catch in here, but wanted to add it so that I was sure the exception being thrown was Not a NPE. Its a file not found exception.

try{
        def writer = new FileWriter( new File(fileSaveLocation));
    } 
    catch ( ex)
    {
        throw(ex)
    }

Edit: Adding the exception that is pushed to the exception handler

Exception:org.codehaus.groovy.grails.web.errors.GrailsWrappedRuntimeException
Cause:org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException

回答1:


It's not because you're referencing something that is null inside the error handler, and so are inadvertently throwing another exception, which is again caught?

can you try changing:

def exception = request.exception.cause.class  

to

def exception = request?.exception?.cause?.class  


来源:https://stackoverflow.com/questions/6777000/grails-error-handler-always-receives-null-pointer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!