Manual handling of Exception usage

Source: Internet
Author: User

    In the process of running the program, inevitably encountered some errors, it is necessary to do some processing of errors, so that the error can be more friendly to display to the user. So here's a description of the use of manual error handling:1, the establishment of the error handler class, inherited fromruntimeexception, as follows
public class ApplicationException extends RuntimeException {public    applicationexception () {    }    Public ApplicationException (String message) {        super (message);    }    Public ApplicationException (Throwable cause) {        super (cause);    }    Public ApplicationException (String message, throwable cause) {        Super (message, cause);    }    Public ApplicationException (String message, Throwable cause,            boolean enablesuppression, Boolean Writablestacktrace) {        super (message, cause, enablesuppression, writablestacktrace);    }}

2. Error handling Configuration
    <!--error Jump page configuration-     <error-page>         <exception-type> Com.bjpowernode.drp.util.applicationexception</exception-type>         <location>/error.jsp</ Location>     </error-page>  

3, error handling program error.jsp (simple interception)
<div align= "center" ><p align= "left" ><span class= "STYLE1" > Error message:</div>    <div><% =exception.getmessage ()%></div>

4, in addition, there are some error code of the rationale, as follows:    1) configuration of the error code in the configuration file
<!--error Jump page configuration-     <error-page>         <error-code>404</error-code>         <location >/http_error.jsp</location>     </error-page>     <error-page>         <error-code>500 </error-code>         <location>/http_error.jsp</location>     </error-page>  

    2) Error handling pageTreatment of http_error.jsp
        <body>            <%                integer errorcode= (integer) request.getattribute ("Javax.servlet.error.status_code");                 When the error codes 404 and 500 are encountered respectively, jump to the corresponding error handling page to process                if (errorcode==404) {                    Response.sendredirect ( Request.getcontextpath () + "/404.jsp");                } else if (errorcode==500) {                    response.sendredirect (Request.getcontextpath () + "/500.jsp");                }            %>        </body>

3) Error handling page processing if it is 404: < Body > The requested page was not found </ Body > if it is: < Body > system error, please contact the system administrator! </body>   

Manual handling of Exception usage

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.