JavaScud | Forum | JIRA | Blog |
  Dashboard > WebWork2文档中文化计划 > ... > Interceptors > Exception Interceptor
  WebWork2文档中文化计划 Log In View a printable version of the current page.  
  Exception Interceptor
Added by scud, last edited by scud on May 19, 2006  (view change)
Labels: 
(None)

这个拦截器提供了异常处理的主要核心功能.异常处理允许你把一个异常映射到一个结果码,就像是action返回一个结果码,而不是抛出意想不到的异常.当一个异常出现,它会被包装成ExceptionHolder放到栈中,这样我们就可以很容易的在结果中使用了

注意:你可以在配置文件中任何一点配置异常映射,但是如果你没有把这个拦截器放在你的拦截器栈中,就不会产生任何影响.建议把这个拦截器放置在栈的第一个,这样可以保证它能捕捉到所有action甚至其它拦截器中出现的异常.

参数

扩展

如果你想自定义异常的发布方式,你可以复写{@link #publishException(com.opensymphony.xwork.ActionInvocation, ExceptionHolder)}.默认实现是把得到的ExceptionHolder放到值栈中.你可以根据需要添加其它逻辑.

例子

<xwork>
    <include file="webwork-default.xml"/>

    <package name="default" extends="webwork-default">
        <global-results>
            <result name="success" type="freemarker">error.ftl</result>
        </global-results>

        <global-exception-mappings>
            <exception-mapping exception="java.lang.Exception" result="error"/>
        </global-exception-mappings>

        <action name="test">
            <interceptor-ref name="exception"/>
            <interceptor-ref name="basicStack"/>
            <exception-mapping exception="com.acme.CustomException" result="custom_error"/>
            <result name="custom_error">custom_error.ftl</result>
            <result name="success" type="freemarker">test.ftl</result>
        </action>
    </package>
</xwork>
Site running on a free Atlassian Confluence Open Source Project License granted to WebWork China. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.3 Build:#808 May 29, 2007) - Bug/feature request - Contact Administrators