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