HttpException.HttpException(String, Exception) Constructor
Assembly: System.Web (in system.web.dll)
public HttpException ( String message, Exception innerException )
public function HttpException ( message : String, innerException : Exception )
Not applicable.
Parameters
- message
The error message displayed to the client when the exception is thrown.
- innerException
The InnerException, if any, that threw the current exception.
When handling exceptions, it can be useful to capture a series of related exceptions with the outer exception being thrown in response to an inner exception.
A reference to the inner exception that caused the outer exception is available from the InnerException property of the outer exception. This mechanism preserves the error information that is carried by earlier exceptions, including the original exceptions, while allowing you to create more meaningful outer exceptions. For more information, see InnerException.
The following code example demonstrates the HttpException constructor of the HttpException class. The CheckNumber method accepts a user-entered value through a text box and checks whether it is an integer. If the value is not an integer, an exception is thrown, and then in the catch block, a new HttpException object is created and thrown. That exception is caught in the Button_Click event handler and the error message is displayed on the browser.
Security Note: |
|---|
| This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview (Visual Studio). |
Security Note: