HttpException Constructor (Int32, String, Int32)
Assembly: System.Web (in system.web.dll)
public HttpException ( int httpCode, String message, int hr )
public function HttpException ( httpCode : int, message : String, hr : int )
Parameters
- httpCode
The HTTP response status code displayed on the client.
- message
The error message displayed to the client when the exception is thrown.
- hr
The exception code that defines the error.
The following code example demonstrates the HttpException constructor of the HttpException class. The user name and e-mail information are entered by the user in the provided text boxes. If any of the text boxes are left blank, an HttpException object is created and thrown. The error code of the HttpException is obtained by the GetHttpCode method and displayed on the Web page.
<html>
<head>
<script language="VJ#" runat="server">
void SubmitButton_Click(Object sender, EventArgs e)
{
try {
if(Textbox1.get_Text().get_Length()==0 ||
Textbox2.get_Text().get_Length()==0) {
// Raise an Exception if the username or the emailfield
// field is empty.
throw new HttpException(901,"User name or e-mail "
+ "ID not provided.",333);
}
else {
MyLabel.set_Text("Hello "+Textbox1.get_Text()+"<br>");
MyLabel.set_Text(MyLabel.get_Text()
+ "The Weekly newsletter is mailed to :"
+ Textbox2.get_Text()+"<br>");
}
}
catch(HttpException ex) {
// Display the error code returned by the GetHttpCode method.
MyLabel.set_Text("<h4><font color=red>The exception is "
+ ex.GetHttpCode() +" - "+ ex.get_Message()
+ "</font></h4>");
}
} //SubmitButton_Click
void Page_Load(Object sender,EventArgs e)
{
MyLabel.set_Text("");
} //Page_Load
</script>
</head>
<body>
<form runat="server" ID="Form1">
<h3>HttpException Example</h3>
Enter UserName and Email
<br><br>
UserName :
<asp:TextBox ID="Textbox1" Runat="server"></asp:TextBox>
<br>
E-mail ID :
<asp:TextBox ID="Textbox2" Runat="server"></asp:TextBox>
<asp:Button ID="Button1" Text="Submit" OnClick="SubmitButton_Click" runat="server" />
<p>
<asp:label id="MyLabel" runat="server" />
</form>
</body>
</html>
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.