Exception handling: exception-mapping elements

Source: Internet
Author: User

exception-mapping element: Configuring declarative exception handling for the current action
There are 2 attributes in the exception-mapping element
Exception: Specifies the type of exception that needs to be captured. The full class name of the exception
Result: Specifies a response result that will be executed when the specified exception is caught, either from the declaration of the current action or from the Global-results declaration.
You can provide a global exception-capture mapping for your application through the global-exception-mappings element. However, any exception-mapping element declared under the Global-exception-mappings element can only refer to a result element declared under the Global-results element
The declarative exception-handling mechanism isThe Exceptionmappinginterceptor Interceptor is responsible for handling, when an exception declared by an exception-mapping element is captured, the Exceptionmappinginterceptor interceptor adds two objects to Valuestack:
Exception: Exception object that represents the exception being caught
Exceptionstack: The stack containing the caught exception
You can display the exception message on the view through the <s:property> tab I: Configure global exceptions (for specific actions) in the configuration file<Actionname= "User_*"class= "actions. Useraction "Method= ' {1} '>              <exception-mappingresult= "Input" Exception= "Java.lang.Exception">              </exception-mapping>               <resultname= "Login_success"type= "redirect">/success.jsp</result>              <result name= "Input">/index.jsp</result></Action>When the program has not been crawled exception, Exceptionmappinginterceptor first go to configure the file to see if there is any configuration of global exception information if any, the exception information will be placed in the stack, or will be reported 500 error: II: can be global-exception-mappings Element provides a global exception-capture mapping for an application<!--Global exception result type -          <Global-results>              <resultname= "Input">/index.jsp</result>          </Global-results>          <!--Global exception capture --          <global-exception-mappings>                 <exception-mappingresult= "Input"Exception= "Java.lang.Exception"> </exception-mapping>          </global-exception-mappings> Exceptionmappinginterceptor Interceptor Source Code Analysis: Public classExceptionmappinginterceptor extends Abstractinterceptor {       @Override    PublicString Intercept (actioninvocation invocation) throws Exception {String result;         Try{result = Invocation.invoke ();        } Catch(Exception e) {            if(islogenabled ()) {handlelogging (e);            } //Get exception configuration information in the configuration file list<exceptionmappingconfig> exceptionmappings = Invocation.getproxy (). GetConfig (). GetExceptionMappi NGS (); String Mappedresult = This. Findresultfromexceptions (Exceptionmappings, e);            if(Mappedresult! = NULL) {result = Mappedresult; //Press the exception information into the value stack publishexception (Invocation, NewExceptionholder (e));            } Else{                Throwe;            }        }         returnresult;    }   //press into the value stack     protected voidpublishexception (actioninvocation invocation, Exceptionholder exceptionholder) {Invocation.getstack (). push (Exceptionholder);    }}

Exception handling: exception-mapping elements

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.