Export (0) Print
Expand All

HttpException Constructor

.NET Framework 1.1

Constructs a new Exception object.

Overload List

Constructs an empty Exception object.

[Visual Basic] Public Sub New()
[C#] public HttpException();
[C++] public: HttpException();
[JScript] public function HttpException();

Constructs an Exception using a supplied error message.

[Visual Basic] Public Sub New(String)
[C#] public HttpException(string);
[C++] public: HttpException(String*);
[JScript] public function HttpException(String);

Constructs an Exception using an HTTP error code and an error message.

[Visual Basic] Public Sub New(Integer, String)
[C#] public HttpException(int, string);
[C++] public: HttpException(int, String*);
[JScript] public function HttpException(int, String);

Constructs an Exception using an error message and the InnerException property.

[Visual Basic] Public Sub New(String, Exception)
[C#] public HttpException(string, Exception);
[C++] public: HttpException(String*, Exception*);
[JScript] public function HttpException(String, Exception);

Constructs an Exception using error message and an exception code.

[Visual Basic] Public Sub New(String, Integer)
[C#] public HttpException(string, int);
[C++] public: HttpException(String*, int);
[JScript] public function HttpException(String, int);

Constructs an Exception using an HTTP error code, an error message, and the InnerException property.

[Visual Basic] Public Sub New(Integer, String, Exception)
[C#] public HttpException(int, string, Exception);
[C++] public: HttpException(int, String*, Exception*);
[JScript] public function HttpException(int, String, Exception);

Constructs an Exception using HTTP error code, an error message, and an exception code.

[Visual Basic] Public Sub New(Integer, String, Integer)
[C#] public HttpException(int, string, int);
[C++] public: HttpException(int, String*, int);
[JScript] public function HttpException(int, String, int);

Example

[Visual Basic, C#] Note   This example shows how to use one of the overloaded versions of the HttpException constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
<!-- 
   The following example demonstrates the HttpException(int,String,int)
   constructor of the HttpException class. The user name and e mail 
   information are entered by the user through the text boxes provided. 
   If any of the text boxes is 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="VB" runat="server">
         Sub SubmitButton_Click(sender As Object, e As EventArgs)
            Try
               If Textbox1.Text.Length = 0 Or Textbox2.Text.Length = 0 Then
                  ' Raise an Exception if the username or emailid field is empty.
                  Throw New HttpException(901, "User name or e-mail ID not provided", 333)
               Else
                  MyLabel.Text = "Hello " & Textbox1.Text & "<br>"
                  MyLabel.Text += "The Weekly newsletter is mailed to :" & Textbox2.Text & "<br>"
               End If
            Catch ex As HttpException
               ' Display the error code returned by the GetHttpCode method.
               MyLabel.Text = "<h4><font color=red>The exception is " & ex.GetHttpCode() & _
                  " - " & ex.Message & "</font></h4>"
            End Try
         End Sub

         Sub Page_Load(sender As Object, e As EventArgs)
            MyLabel.Text = ""
         End Sub
      </script>
   </head>

   <body>
      <form runat="server" ID="Form1">
         <h3>HttpException Example</h3>
         Enter User name and E-mail
         <br><br>
         User Name:
         <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>

[C#] 
<!-- 
   The following example demonstrates the HttpException(int,String,int)
   constructor of the HttpException class. The user name and e mail 
   information are entered by the user through the text boxes provided. 
   If any of the text boxes is 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="C#" runat="server">
         void SubmitButton_Click(Object sender, EventArgs e)
         {
            try
            {
               if(Textbox1.Text.Length==0 || Textbox2.Text.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.Text="Hello "+Textbox1.Text+"<br>";
                  MyLabel.Text+="The Weekly newsletter is mailed to :"+
                           Textbox2.Text+"<br>";
               }
            }
            catch(HttpException ex)
            { 
               // Display the error code returned by the GetHttpCode method.
               MyLabel.Text="<h4><font color=red>The exception is "+
                  ex.GetHttpCode() +" - "+ ex.Message + "</font></h4>";
            }
         }

         void Page_Load(object sender,EventArgs e)
         {
            MyLabel.Text="";
         }
      </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>

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

HttpException Class | HttpException Members | System.Web Namespace

Show:
© 2014 Microsoft