Customizing Error Pages
page 1 of 3
Published: 02 Jun 2004
Unedited - Community Contributed
When developing any application no matter if it is developed in C# or VB.NET you will always want to handle and respond to any type of errors for obvious reasons. If you think about it there is nothing more embarrassing than an error being seen by your end users. I will discuss using the global.asax and web.config to customize errors. By utilizing one or both of these files you can customize exactly how you wish to handle any errors from you application.
by Steven Swafford
Average Rating: 
Views (Total / Last 10 Days): 20296/ 83

Exception Management Introduction

There are four main types of errors that you will encounter at some point in time.

Four main types of errors:
1. Configuration errors - Errors that are caused by problems that are found in the web.config or the machine.config files.
2. Parser errors - The cause of this type of error is incorrect syntax in an ASP.Net page.
3. Compilation errors - This error is fired via the compiler.
4. Runtime errors - This error is fired at page execution.

The term you will grow to love is simply called exception handling and what this means is anything that happens in your application that is unexpected or undesired.

Properties of the exception class:
1. StackTrace - Gets a string representation of the frames on the call stack at the time the current exception was thrown.
2. InnerException - Gets the exception instance that caused the current exception.
3. Message - Gets a message that describes the current exception.
4. HelpLink - Gets or sets a link to the help file associated with this exception.
5. Source - Gets or sets the name of the application or the object that causes the error.
6. TargetSite - Gets the method that throws the current exception.
7. HResult - Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

Be sure to examine the exception class.

Quick Example Catch
Whenever you execute a statement that has the potential to fail; you will want to wrap the statement in a try…catch block. This way you can handle any runtime errors that may result from the statement.

To start off with catches, you have use try....catch….finally syntax. It looks like this:

    // some part of the coding whereupon it might fail at runtime 
catch (Exception e) 
    //  block of code that does error handling 
    // coding that will run no matter what happens before this point 

Now that you have the general knowledge of the types of errors that you may encounter and a basic example of the try...catch... finally syntax it is time to move on to a more in depth discussion.

View Entire Article

User Comments

Title: Very good info, thanks   
Name: Joe
Date: 2004-06-14 4:49:41 AM
This was very helpful for me.

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-05-29 11:05:05 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search