HttpException 생성자

정의

HttpException 클래스의 새 인스턴스를 초기화합니다.

오버로드

HttpException()

HttpException 클래스의 새 인스턴스를 초기화하여 빈 HttpException 개체를 만듭니다.

HttpException(String)

제공된 오류 메시지를 사용하여 HttpException 클래스의 새 인스턴스를 초기화합니다.

HttpException(Int32, String)

HTTP 응답 상태 코드 및 오류 메시지를 사용하여 HttpException 클래스의 새 인스턴스를 초기화합니다.

HttpException(SerializationInfo, StreamingContext)

serialize된 데이터를 사용하여 HttpException 클래스의 새 인스턴스를 초기화합니다.

HttpException(String, Exception)

오류 메시지와 HttpException 속성을 사용하여 InnerException 클래스의 새 인스턴스를 초기화합니다.

HttpException(String, Int32)

오류 메시지와 예외 코드를 사용하여 HttpException 클래스의 새 인스턴스를 초기화합니다.

HttpException(Int32, String, Exception)

HTTP 응답 상태 코드, 오류 메시지 및 HttpException 속성을 사용하여 InnerException 클래스의 새 인스턴스를 초기화합니다.

HttpException(Int32, String, Int32)

HTTP 응답 상태 코드, 오류 메시지 및 예외 코드를 사용하여 HttpException 클래스의 새 인스턴스를 초기화합니다.

HttpException()

HttpException 클래스의 새 인스턴스를 초기화하여 빈 HttpException 개체를 만듭니다.

public:
 HttpException();
public HttpException ();
Public Sub New ()

예제

다음 코드 예제에서는 클래스의 HttpException 생성자를 보여 줍니다 HttpException . 이 메서드는 CheckNumber 입력란을 통해 사용자가 입력한 값을 수락하고 정수인지 여부를 확인합니다. 값이 정수가 아니면 예외가 throw되고 새 HttpException 개체가 만들어지고 throw됩니다. 이 예외는 이벤트 처리기에서 Button_Click catch되고 오류 메시지가 브라우저에 표시됩니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.


<html xmlns="http://www.w3.org/1999/xhtml" >
   <head>
    <title>
            Example for HttpException
         </title>
<script language="C#" runat="server">
         void CheckNumber()
         {
            try
            {
               // Check whether the value is an integer.
               String convertInt = textbox1.Text;
               Convert.ToInt32(convertInt);
            }
            catch(Exception e)
            {
               // Throw a 'HttpException' object.
               throw new HttpException();
            }
         }
      
         void Button_Click(Object sender, EventArgs e)
         {
            try
            {
               CheckNumber();
               label1.Text = "The integer value you entered is: "+textbox1.Text;
            }
            catch(HttpException exp)
            {
               label1.Text = "<font color='red'>An HttpException was raised!:"
                  + " The value entered in the textbox is not an integer.</font>";
            }
         }

         void page_load(object sender,EventArgs e)
         {
            label1.Text="";
         }
      </script>
   </head>
   
   <body>
      <center>
         <h3>
            Example for HttpException
         </h3>
      </center>
      
      <form id="WebForm9" method="post" runat="server">
         <center>
         <br />
         <b>Enter a value in the text box.</b>
         <br />
         <asp:TextBox Runat="server" ID="textbox1"></asp:TextBox>
         <br />
         <asp:Button Text="Click Here" OnClick="Button_Click" Runat="server"></asp:Button>
         <br />
         <b><asp:Label Runat="server" ID="label1"></asp:Label></b>
         </center>
      </form>
   </body>
</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
   <head>
    <title>Example for HttpException</title>
<script language="VB" runat="server">
         Sub CheckNumber()
            Try
               ' Check whether the value is an integer.
               Dim convertInt As [String] = textbox1.Text
               Convert.ToInt32(convertInt)
            Catch e As Exception
               ' Throw the 'HttpException' object.
               Throw New HttpException()
            End Try
         End Sub 'CheckNumber
 
         Sub Button_Click(sender As [Object], e As EventArgs)
            Try
               CheckNumber()
               label1.Text = "The integer value you entered is: " + textbox1.Text
            Catch exp As HttpException
               label1.Text = "<font color='red'>An HttpException was raised!:" _
                  & " The value entered in the textbox is not an integer</font>"
            End Try
         End Sub 'Button_Click
       
         Sub Page_Load(sender As [Object], e As EventArgs)
            label1.Text=""
         End Sub
      </script>
   </head>

   <body>
      <center>
         <h3>Example for HttpException</h3>
      </center>
      <form id="WebForm9" method="post" runat="server">
         <center>
            <b>Enter a value in the text box.</b>
            <asp:TextBox Runat="server" ID="textbox1"></asp:TextBox>
            <br />
            <asp:Button Text="Click Here" OnClick="Button_Click" Runat="server"></asp:Button>
            <br />
            <b><asp:Label Runat="server" ID="label1"></asp:Label></b>
         </center>
      </form>
   </body>
</html>

설명

예외를 처리할 때 내부 예외에 대한 응답으로 외부 예외가 throw되는 일련의 관련 예외를 캡처하는 것이 유용할 수 있습니다.

외부 예외를 발생시킨 내부 예외에 대한 참조는 외부 예외의 InnerException 속성에서 사용할 수 있습니다. 이 메커니즘은 원래 예외를 포함하여 이전 예외에 의해 수행되는 오류 정보를 유지하면서 보다 의미 있는 외부 예외를 만들 수 있도록 합니다. 자세한 내용은 InnerException를 참조하세요.

추가 정보

적용 대상

HttpException(String)

제공된 오류 메시지를 사용하여 HttpException 클래스의 새 인스턴스를 초기화합니다.

public:
 HttpException(System::String ^ message);
public HttpException (string message);
new System.Web.HttpException : string -> System.Web.HttpException
Public Sub New (message As String)

매개 변수

message
String

예외가 throw될 때 클라이언트에 표시되는 오류 메시지입니다.

예제

다음 코드 예제에서는 클래스의 HttpException 생성자를 보여 줍니다 HttpException . HttpException 사용자가 입력한 값이 0이면 throw됩니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.

if (Num == 0)
{
   throw new HttpException("No value entered");
}
If Num = 0 Then
   Throw New HttpException("No value entered")
end if

추가 정보

적용 대상

HttpException(Int32, String)

HTTP 응답 상태 코드 및 오류 메시지를 사용하여 HttpException 클래스의 새 인스턴스를 초기화합니다.

public:
 HttpException(int httpCode, System::String ^ message);
public HttpException (int httpCode, string message);
new System.Web.HttpException : int * string -> System.Web.HttpException
Public Sub New (httpCode As Integer, message As String)

매개 변수

httpCode
Int32

이 오류에 해당하는 클라이언트로 보낸 HTTP 응답 상태 코드입니다.

message
String

예외가 throw될 때 클라이언트에 표시되는 오류 메시지입니다.

추가 정보

적용 대상

HttpException(SerializationInfo, StreamingContext)

serialize된 데이터를 사용하여 HttpException 클래스의 새 인스턴스를 초기화합니다.

protected:
 HttpException(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected HttpException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new System.Web.HttpException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Web.HttpException
Protected Sub New (info As SerializationInfo, context As StreamingContext)

매개 변수

info
SerializationInfo

throw되는 예외에 대해 serialize된 개체 데이터를 보유하는 SerializationInfo 개체입니다.

context
StreamingContext

소스 또는 대상에 대한 컨텍스트 정보를 보유하는 StreamingContext입니다.

설명

HttpException 역직렬화 중에 생성자가 호출되어 스트림을 통해 전송되는 예외 개체를 다시 구성합니다. 자세한 내용은 XML 및 SOAP Serialization합니다.

추가 정보

적용 대상

HttpException(String, Exception)

오류 메시지와 HttpException 속성을 사용하여 InnerException 클래스의 새 인스턴스를 초기화합니다.

public:
 HttpException(System::String ^ message, Exception ^ innerException);
public HttpException (string message, Exception innerException);
new System.Web.HttpException : string * Exception -> System.Web.HttpException
Public Sub New (message As String, innerException As Exception)

매개 변수

message
String

예외가 throw될 때 클라이언트에 표시되는 오류 메시지입니다.

innerException
Exception

현재 예외를 throw한 InnerException(있는 경우)입니다.

예제

다음 코드 예제에서는 클래스의 HttpException 생성자를 보여 줍니다 HttpException . 이 메서드는 CheckNumber 입력란을 통해 사용자가 입력한 값을 수락하고 정수인지 여부를 확인합니다. 값이 정수가 아니면 예외가 throw된 다음 catch 블록에서 새 HttpException 개체가 만들어지고 throw됩니다. 이 예외는 이벤트 처리기에서 Button_Click catch되고 오류 메시지가 브라우저에 표시됩니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.


<html xmlns="http://www.w3.org/1999/xhtml" >
   <head>
    <title>Example for HttpException</title>
<script language="C#" runat="server">    
         void CheckNumber()
         {
            try
            {
               // Check whether the value is an integer.
               String convertInt= textbox1.Text;
               Convert.ToInt32(convertInt);
            }
            catch(Exception e)
            {
               // Throw an HttpException object with a message.
               throw new HttpException("THe value entered in the text box is not a integer", e);
            }
         }
      
         void Button_Click(Object sender, EventArgs e)
         {
            try
            {
               CheckNumber();
               label1.Text = "The integer value you entered is: " + textbox1.Text;
            }
            catch(HttpException exp)
            {
               // Display the exception thrown.
               label1.Text = "<font color='red'>An HttpException was raised: " + exp.Message + "</font>";
               Exception myInnerException = exp.InnerException;
               label2.Text = "InnerException is : " + myInnerException.GetType();
            }
         }

         void page_load(Object sender,EventArgs e)
         {
            label1.Text="";
            label2.Text="";
         }
      </script>
   </head>

   <body>
      <center>
         <h3>Example for HttpException</h3>
      </center>
      <form id="Form1" method="post" runat="server">
         <center>
            <b>Enter the value in the text box </b>
            <br />
            <asp:TextBox Runat="server" ID="textbox1"></asp:TextBox>
            <br />
            <asp:Button Text="Click Here" OnClick="Button_Click" Runat="server" ID="Button1"></asp:Button>
            <br />
            <b>
               <asp:Label Runat="server" ID="label1"></asp:Label>
               <br />
               <asp:Label Runat="server" ID="label2"></asp:Label>
            </b>
         </center>
      </form>
   </body>
</html>

<html xmlns="http://www.w3.org/1999/xhtml" >
   <head>
    <title>Example for HttpException</title>
<script language="VB" runat="server">  
         Sub CheckNumber()
            Try
               ' Check whether the value is an integer.
               Dim convertInt As [String] = textbox1.Text
               Convert.ToInt32(convertInt)
            Catch e As Exception
               ' Throw an HttpException object with a message.
               Throw New HttpException("The value entered in the textbox is not a integer", e)
            End Try
         End Sub 'CheckNumber
       
         Sub Button_Click(sender As [Object], e As EventArgs)
            Try
               CheckNumber()
               label1.Text = "The integer value you entered is: " + textbox1.Text
            Catch exp As HttpException
               ' Display the exception thrown.
               label1.Text = "<font color='red'>An HttpException was raised!: " + exp.Message + "</font>"
               Dim myInnerException As Exception = exp.InnerException
               label2.Text = "InnerException is : " + myInnerException.GetType().ToString()
            End Try
         End Sub 'Button_Click
       
         Sub page_load(sender As [Object], e As EventArgs)
            label1.Text=""
            label2.Text="" 
         End Sub
      </script>
   </head>

   <body>
      <center>
      <h3>Example for HttpException</h3>
      <form id="WebForm9" method="post" runat="server">
         <b>Enter the value in the text box </b>
         <asp:TextBox Runat="server" ID="textbox1"></asp:TextBox>
         <br />
         <asp:Button Text="Click Here" OnClick="Button_Click" Runat="server" ID="Button1"></asp:Button>
         <br />
         <b>
         <asp:Label Runat="server" ID="label1"></asp:Label>
         <br />
         <asp:Label Runat="server" ID="label2"></asp:Label>
         </b>
      </form>
      </center>
   </body>
</html>

설명

예외를 처리할 때 내부 예외에 대한 응답으로 외부 예외가 throw되는 일련의 관련 예외를 캡처하는 것이 유용할 수 있습니다.

외부 예외를 발생시킨 내부 예외에 대한 참조는 외부 예외의 InnerException 속성에서 사용할 수 있습니다. 이 메커니즘은 원래 예외를 포함하여 이전 예외에 의해 수행되는 오류 정보를 유지하면서 보다 의미 있는 외부 예외를 만들 수 있도록 합니다. 자세한 내용은 InnerException를 참조하세요.

추가 정보

적용 대상

HttpException(String, Int32)

오류 메시지와 예외 코드를 사용하여 HttpException 클래스의 새 인스턴스를 초기화합니다.

public:
 HttpException(System::String ^ message, int hr);
public HttpException (string message, int hr);
new System.Web.HttpException : string * int -> System.Web.HttpException
Public Sub New (message As String, hr As Integer)

매개 변수

message
String

예외가 throw될 때 클라이언트에 표시되는 오류 메시지입니다.

hr
Int32

오류를 정의하는 예외 코드입니다.

예제

다음 코드 예제에서는 클래스의 HttpException 생성자를 보여 줍니다 HttpException . HttpException 사용자가 입력한 값이 0이면 예외가 throw됩니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.

if (Num == 0)
{
   throw new HttpException("No value entered", 100);
}
If Num = 0 Then
   Throw New HttpException("No value entered", 100)
end if

추가 정보

적용 대상

HttpException(Int32, String, Exception)

HTTP 응답 상태 코드, 오류 메시지 및 HttpException 속성을 사용하여 InnerException 클래스의 새 인스턴스를 초기화합니다.

public:
 HttpException(int httpCode, System::String ^ message, Exception ^ innerException);
public HttpException (int httpCode, string message, Exception innerException);
new System.Web.HttpException : int * string * Exception -> System.Web.HttpException
Public Sub New (httpCode As Integer, message As String, innerException As Exception)

매개 변수

httpCode
Int32

클라이언트에 표시되는 HTTP 응답 상태 코드입니다.

message
String

예외가 throw될 때 클라이언트에 표시되는 오류 메시지입니다.

innerException
Exception

현재 예외를 throw한 InnerException(있는 경우)입니다.

예제

다음 코드 예제에서는 클래스의 HttpException 생성자를 보여 줍니다 HttpException . 이 메서드는 CheckNumber 사용자가 입력한 값을 수락하고 정수인지 여부를 확인합니다. 값이 정수가 아니면 예외가 throw된 다음 HTTP 응답 상태 코드, 예외 메시지 및 내부 예외가 포함된 새 HttpException 개체가 만들어집니다. 이 예외는 이벤트 처리기에서 Button_Click catch되고 오류 메시지, 오류 코드 및 내부 예외가 표시됩니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.


<%@ Import Namespace="System.Drawing" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
   <head>
    <title>Example for HttpException</title>
<script language="C#" runat="server">
         void CheckNumber()
         {
            try
            {
               // Check whether the value is an integer.
               String convertInt = textbox1.Text;
               Convert.ToInt32(convertInt);
            }
            catch(Exception ex)
            {
               // Throw an HttpException object that contains the HTTP error code,
               // message, and inner exception.
               throw new HttpException(500, "The entered value is not an integer.", ex);
            }
         }
         
         void Button_Click(Object sender, EventArgs e)
         {
            try
            {
               CheckNumber();
               label1.Text = "The integer value you entered is: " + textbox1.Text;
            }
            catch(HttpException exp)
            {
               // Display the exception thrown.
               label1.ForeColor = Color.Red;
               label1.Text = "An HttpException was raised!: " + exp.Message;
               Exception myInnerException = exp.InnerException;
               
               // Display the inner exception.
               label2.Text = "The InnerException is : " + myInnerException.GetType();
                
            }
         }
     
         void page_load(Object sender,EventArgs e)
         {
           label1.Text="";
           label2.Text="";
         }

      </script>
   </head>

   <body>
      <center>
         <h3>Example for HttpException</h3>
         <form id="WebForm9" method="post" runat="server">
            <b>Enter the value in the text box </b>
            <br />
            <asp:TextBox Runat="server" ID="textbox1"></asp:TextBox>
            <br />
            <asp:Button Text="Click Here" OnClick="Button_Click" Runat="server" ID="Button1"></asp:Button>
            <br />
            <b>
               <asp:Label Runat="server" ID="label1"></asp:Label>
               <br />
               <asp:Label Runat="server" ID="label2"></asp:Label>
            </b>
         </form>
      </center>
   </body>
</html>

<%@ Import Namespace="System.Drawing" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
   <head>
    <title>Example for HttpException</title>
<script language="VB" runat="server">
         Sub CheckNumber()
            Try
               'Check whether the value is integer.
               Dim convertInt As [String] = textbox1.Text
               Convert.ToInt32(convertInt)
            Catch ex As Exception
               ' Throw an HttpException object that contains the HTTP error code,
               ' message, and inner exception.
               Throw New HttpException(500, "The entered value is not an integer.", ex)
            End Try
         End Sub
 
         Sub Button_Click(sender As [Object], e As EventArgs)
            Try
               CheckNumber()
               label1.Text = "The integer Value you entered is: " & textbox1.Text

            Catch exp As HttpException
               ' Display the Exception thrown.
               label1.ForeColor = Color.Red
               label1.Text = "An HttpException was raised: " & exp.Message

               Dim myInnerException As Exception = exp.InnerException

               ' Display the inner exception.
               label2.Text = "InnerException is : " & myInnerException.GetType().ToString()
                
            End Try
         End Sub 

         Sub page_load(sender As [Object], e As EventArgs)
            label1.Text = ""
            label2.Text = ""
         End Sub 
      </script>
   </head>

   <body>
      <center>
         <h3>Example for HttpException</h3>
         <form id="WebForm9" method="post" runat="server">
            <b>Enter the value in the text box.</b>
            <asp:TextBox Runat="server" ID="textbox1"></asp:TextBox>
            <br />
            <asp:Button Text="Click Here" OnClick="Button_Click" Runat="server" ID="Button1"></asp:Button>
            <br />
            <b>
            <asp:Label Runat="server" ID="label1"></asp:Label>
            <br />
            <asp:Label Runat="server" ID="label2"></asp:Label>
            </b>
         </form>
      </center>
   </body>
</html>

설명

예외를 처리할 때 내부 예외에 대한 응답으로 외부 예외가 throw되는 일련의 관련 예외를 캡처하는 것이 유용할 수 있습니다.

외부 예외를 발생시킨 내부 예외에 대한 참조는 외부 예외의 InnerException 속성에서 사용할 수 있습니다. 이 메커니즘은 원래 예외를 포함하여 이전 예외에 의해 수행되는 오류 정보를 유지하면서 보다 의미 있는 외부 예외를 만들 수 있도록 합니다. 자세한 내용은 InnerException를 참조하세요.

추가 정보

적용 대상

HttpException(Int32, String, Int32)

HTTP 응답 상태 코드, 오류 메시지 및 예외 코드를 사용하여 HttpException 클래스의 새 인스턴스를 초기화합니다.

public:
 HttpException(int httpCode, System::String ^ message, int hr);
public HttpException (int httpCode, string message, int hr);
new System.Web.HttpException : int * string * int -> System.Web.HttpException
Public Sub New (httpCode As Integer, message As String, hr As Integer)

매개 변수

httpCode
Int32

클라이언트에 표시되는 HTTP 응답 상태 코드입니다.

message
String

예외가 throw될 때 클라이언트에 표시되는 오류 메시지입니다.

hr
Int32

오류를 정의하는 예외 코드입니다.

예제

다음 코드 예제에서는 클래스의 HttpException 생성자를 보여 줍니다 HttpException . 사용자 이름 및 전자 메일 정보는 제공된 텍스트 상자에 사용자가 입력합니다. 텍스트 상자가 비어 있으면 개체가 HttpException 만들어지고 throw됩니다. 오류 HttpException 코드는 메서드에서 GetHttpCode 가져오고 웹 페이지에 표시됩니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
   <head>
    <title>HttpException Example</title>
<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 email 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 />
         Email ID :
         <asp:TextBox ID="Textbox2" Runat="server"></asp:TextBox>
         <asp:Button ID="Button1" Text="Submit" OnClick="SubmitButton_Click" runat="server" />
         <br />
         <asp:label id="MyLabel" runat="server" />
      </form>
   </body>
</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
   <head>
    <title>HttpException Example</title>
<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 email 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 Email
         <br /><br />
         User Name:
         <asp:TextBox ID="Textbox1" Runat="server"></asp:TextBox>
         <br />
         Email ID:
         <asp:TextBox ID="Textbox2" Runat="server"></asp:TextBox>
         <asp:Button ID="Button1" Text="Submit" OnClick="SubmitButton_Click" runat="server"/>
         <br />
         <asp:label id="MyLabel" runat="server"/>
      </form>
   </body>
</html>

추가 정보

적용 대상