DekGenius.com
[ Team LiB ] Previous Section Next Section

Chapter 15. The HttpException Class

The HttpException class provides a container for communicating error information from various classes used in ASP.NET. The Page, HttpRequest, HttpResponse, HttpServerUtility, and other classes all use the HttpException class to communicate information about errors that occur when calling their methods or properties.

The HttpException class is derived from the Exception class, the base class for all exceptions in the .NET Framework. HttpException adds two methods, GetHtmlErrorMessage and GetHttpCode, as well as other constructor overloads that create HttpException instances based on HTTP error codes.

In addition to its role in communicating error information from the Request, Response, and other ASP.NET intrinsic objects, the HttpException class can be useful in communicating error information from custom components or controls that communicate via HTTP. When an HTTP error occurs in such a component, you can use one of the constructor overloads for the HttpException class to create an instance of HttpException that contains the HTTP status code associated with the result, along with a custom error message, if desired, to the client of the component. This allows you to provide clients with rich, specific error information that they can handle as they choose. Table 15-1 lists the properties, collections, and methods exposed by the HttpException class.

Table 15-1. HttpException class summary

Properties

Methods (public instance)

ErrorCode (inherited from Exception)

GetBaseException (inherited from Exception)

HelpLink (inherited from Exception)

GetHtmlErrorMessage

InnerException (inherited from Exception)

GetHttpCode

Message (inherited from Exception)

ToString (inherited from Exception)

Source (inherited from Exception)

StackTrace (inherited from Exception)

TargetSite (inherited from Exception)

 

    [ Team LiB ] Previous Section Next Section