" configuration item."/> " configuration item.">
Home >Backend Development >C#.Net Tutorial >What is the error handling mechanism in .net?
.NET provides four error handling mechanisms, namely: 1. "Page_Error" event; 2. ErrorPage attribute; 3. "Application_Error" event; 4. "930ac17b94b9e98609d20e97126e0d94" configuration item.
.NET provides four error handling mechanisms, namely: Page_Error event, ErrorPage attribute, Application_Error event, 930ac17b94b9e98609d20e97126e0d94 Configuration items. The following article will introduce these four mechanisms to you, hoping to be helpful to you.
Four error handling mechanisms of .NET:
1, Page_Error event
The Page_Error event provides a way to capture errors that occur at the page level. We can just display an error message, or we can log an event or perform some other action.
2. ErrorPage attribute
The ErrorPage attribute is used to get or set the error page. When an unhandled page exception occurs, the requested browser will be Redirect to this page.
Note: The ErrorPage property can be set almost at any time on the page to determine which page will be redirected to when an error occurs on the page.
Note: For the ErrorPage attribute to work, the mode attribute in the 930ac17b94b9e98609d20e97126e0d94 configuration item must be set to "On".
3. Application_Error event
The Application_Error event captures errors that occur in the application. Because events occur application-wide, you can log application error information or handle other application-level errors that may occur. Add the following code to the Global.asax file and it will be OK.
4. The 930ac17b94b9e98609d20e97126e0d94 configuration item
The 930ac17b94b9e98609d20e97126e0d94 configuration item in the web.config configuration file can specify the redirect page as Default error page defaultRedirect or specify a specific page based on the HTTP error code raised. This custom page is displayed if an error occurs that was not caught at any previous level of the application.
Example:
<customErrors mode="On" defaultRedirect="~/ErrorHandling/ApplicationError.html"> <error statusCode="404" redirect="~/ErrorHandling/404.html" /> </customErrors>
Priority:
##There is a certain priority between these four error handling mechanisms Sequence: Page_Error event> ErrorPage property> Application_Error event> 930ac17b94b9e98609d20e97126e0d94 configuration item. Recommended video tutorials: "ASP.NET Tutorial", "C# Tutorial"
The above is the detailed content of What is the error handling mechanism in .net?. For more information, please follow other related articles on the PHP Chinese website!