English 中文(简体)
简单易懂
原标题:SimpleMappingExceptionResolver vs ExceptionFilter

目前,我正在利用“海关服务包”处理一项申请,以追捕所有例外:

  <filter-mapping>
    <filter-name>ExceptionFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

以及

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

try {
    chain.doFilter(request, response);
} catch (Throwable t) {
        if (request instanceof HttpServletRequest) {
            log.error(((HttpServletRequest) request).getRequestURL());
        }
        log.error("Exception:", t);
        String path = "/error.do";
        request.getRequestDispatcher(path).forward(request, response);
}
}

After investigating for some time I have found SimpleMappingExceptionResolver as an easy way to h以及le exception 以及 view mappings 以及 as I see I can not use both but I can not see any reason to prefer one method above the other one.

I underst以及 that it is easier to map diferent errors to different views using the resolver but we only use one error view, so I am more concerned about perfomance of both solutions, if one of the will be able to h以及le a broader range of exceptions 以及 such things.

Thanks in advance to all of you Spring experts

问题回答

To be honest: throwing an exception in one of the most expensive (in terms of perfomance) things you can do in Java. (Don t get me wrong, this is NO statement against using Exceptions.). But if you serious run in an performance problem because you need to process to much exceptions with one of that filters, then you definitely have an other really really serious problem.

因此,你不应想到的是,拖拉机或准尉的运行时间。 想更多地了解哪一个更适合你的项目,其方式是减少法典、更好理解的法典、减少ug。





相关问题
handling exceptions IN Action Filters

Is there a better way to handle exceptions that occur inside an Action Filter itself in ASP .NET MVC? There re 2 ways I can think of at the moment. Using a try catch and setting the HTTP Status ...

既可捕获,又可举出例外。

我有一种办法,可以进入亚洲开发银行,因此,我国的亚行在多瑙河航道中的所有 st子都位于一个试捕区。 它正在追捕Kexception

Cross compiler exception handling - Can it be done safely?

I am doing some maintenance on a C++ windows dll library that is required to work with different VC++ compilers (as I don’t want to address different mangling schemes). I have already eliminated any ...

File Handling Issue

I am developing a tool in c#, at one instance I start writing into a xml file continuously using my tool,when i suddenly restart my machine the particular xml file gets corrupted, what is the reason ...

Watch a memory location/install data breakpoint from code?

We have a memory overwrite problem. At some point, during the course of our program, a memory location is being overwritten and causing our program to crash. the problem happens only in release mode. ...

Unit Test for Exceptions Message

Is there a simple (Attribute-driven) way to have the following test fail on the message of the exception. [TestMethod()] [ExpectedException(typeof(ArgumentException))] public void ExceptionTestTest() ...

热门标签