net错误处理机制(.net error handling mechanism).docVIP

  • 3
  • 0
  • 约3.63千字
  • 约 5页
  • 2017-09-05 发布于河南
  • 举报

net错误处理机制(.net error handling mechanism).doc

net错误处理机制(.net error handling mechanism)

net错误处理机制(.net error handling mechanism) A provides 4 error mechanism: Page_Error event ErrorPage attribute Application_Error event customErrors configuration The Page_Error event The Page_Error event provides a capture at the page level error method. You can only display the error message (as shown in the example code below), you can also record the events or perform some other operation. Private void Page_Load (object sender, System.EventArgs E) User code to {/ / Put initialize the page here Throw new Exception (Page Error!); } Protected void Page_Error (object sender, EventArgs E) { Exception = Server.GetLastError (objErr) (.GetBaseException); Response.Write (Error: + objErr.Message); (Server.ClearError); / / also should pay attention to the use of this code } Note: this example shows the detailed error information in the browser, provides this sample only to explain. To the end user application displays detailed information must be careful. A more appropriate approach is to display a message to inform the user, has the error occurred, and then the specific error details recorded in the log. The ErrorPage property You can set the ErrorPage attribute in the page at any time, so as to determine the error occurred when the page will redirect to any page. Let the ErrorPage attribute can play a role in the customErrors configuration in the mode property must be set to On. This.ErrorPage = ~/ErrorHandling/PageError.html; If Page_Error and ErrorPage are present, when thrown Exception, page execution order is? The page will first execute Page_Error event handling function, if the Page_Error () function call Server.ClearError () in the event of abnormal information, do not jump to the specified ErrorPage property page; if you do not call Server.ClearError (Exception), the information will continue to throw up, the page will jump to the specified ErrorPage page. This proves the priority order: Page_Error event ErrorPage attribute. . The Application_Error event Similar to

文档评论(0)

1亿VIP精品文档

相关文档