HttpExceptionとは? わかりやすく解説

HttpException クラス

HTTP 要求の処理中に発生した例外を説明します。

名前空間: System.Web
アセンブリ: System.Web (system.web.dll 内)
構文構文

<SerializableAttribute> _
Public Class HttpException
    Inherits ExternalException
Dim instance As HttpException
[SerializableAttribute] 
public class HttpException : ExternalException
[SerializableAttribute] 
public ref class HttpException : public
 ExternalException
/** @attribute SerializableAttribute() */ 
public class HttpException extends ExternalException
SerializableAttribute 
public class HttpException extends
 ExternalException
解説解説
使用例使用例

HttpException クラスを使用してカスタマイズされた例外を発生させる方法を次のコード例に示します。Button_Click メソッドは、クリックされたボタンを判断し、CheckNumber メソッドまたは CheckBoolean メソッドを呼び出します。ユーザーがテキスト ボックスに入力した値が必要な型と一致しない場合は、HttpException 例外が作成され、エラーの型に基づいてカスタマイズされたメッセージと共にスローされます。

<%@ Page language="VB" %>

<script 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 with customized message.
      Throw New HttpException("not
 an integer")

    End Try

  End Sub

  Sub CheckBoolean()
    
    Try

      ' Check whether the value is an boolean.
      Dim convertBool As String
 = textbox1.Text
      Convert.ToBoolean(convertBool)

    Catch e As Exception

      ' Throw an HttpException with customized message.
      Throw New HttpException("not
 a boolean")

    End Try

  End Sub


  Sub Button_Click(ByVal sender As
 [Object], ByVal e As EventArgs)
    
    Try

      ' Check to see which button was clicked.
      Dim b As Button = CType(sender, Button)
      If b.ID.StartsWith("button1")
 Then
        CheckNumber()
      ElseIf b.ID.StartsWith("button2")
 Then
        CheckBoolean()
      End If

      label1.Text = "You entered: " + textbox1.Text
      label1.ForeColor = System.Drawing.Color.Black

      ' Catch the HttpException.
    Catch exp As HttpException

      label1.Text = "An HttpException was raised. "
 + "The value entered in the textbox is " + exp.Message.ToString()
      label1.ForeColor = System.Drawing.Color.Red

    End Try

  End Sub

</script>

<html>
   <head>
     <title>HttpException Example</title>
   </head>
   <body>
     <h3>HttpException Example</h3>
      
     <form id="Form1" runat="server">
        <br />
        <b>Enter a value in the text box.</b>
        <br />
        <asp:TextBox ID="textbox1" 
                     Runat="server">
        </asp:TextBox>
        <br />
        <asp:Button ID="button1"
                    Text="Check for integer."  
                    OnClick="Button_Click" 
                    Runat="server">
        </asp:Button>
        <br />
        <asp:Button ID="button2"
                    Text="Check for boolean." 
                    OnClick="Button_Click" 
                    Runat="server">
        </asp:Button>
        <br />
        <asp:Label ID="label1" 
                   Runat="server">
        </asp:Label>
     </form>
   </body>
</html>
<%@ Page language="C#" %>

<script 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 with customized message.
      throw new HttpException("not an integer");
    }
  }
  void CheckBoolean()
  {
    try
    {
      // Check whether the value is an boolean.
      String convertBool = textbox1.Text;
      Convert.ToBoolean(convertBool);
    }
    catch (Exception e)
    {
      // Throw an HttpException with customized message.
      throw new HttpException("not a boolean");
    }
  }

  void Button_Click(Object sender, EventArgs e)
  {
    try
    {
      // Check to see which button was clicked.
      Button b = (Button)sender;
      if (b.ID.StartsWith("button1"))
        CheckNumber();
      else if (b.ID.StartsWith("button2"))
        CheckBoolean();
      
      label1.Text = "You entered: " + textbox1.Text;
      label1.ForeColor = System.Drawing.Color.Black;
    }
    // Catch the HttpException.
    catch (HttpException exp)
    {
      label1.Text = "An HttpException was raised. "
         + "The value entered in the textbox is " +
 exp.Message.ToString();
      label1.ForeColor = System.Drawing.Color.Red;
    }
  }

</script>
<html>
   <head>
     <title>HttpException Example</title>
   </head>
   <body>
     <h3>HttpException Example</h3>
      
     <form runat="server">
        <br />
        <b>Enter a value in the text box.</b>
        <br />
        <asp:TextBox ID="textbox1" 
                     Runat="server">
        </asp:TextBox>
        <br />
        <asp:Button ID="button1"
                    Text="Check for integer."  
                    OnClick="Button_Click" 
                    Runat="server">
        </asp:Button>
        <br />
        <asp:Button ID="button2"
                    Text="Check for boolean." 
                    OnClick="Button_Click" 
                    Runat="server">
        </asp:Button>
        <br />
        <asp:Label ID="label1" 
                   Runat="server">
        </asp:Label>
     </form>
   </body>
</html>
.NET Framework のセキュリティ.NET Framework のセキュリティ
継承階層継承階層
System.Object
   System.Exception
     System.SystemException
       System.Runtime.InteropServices.ExternalException
        System.Web.HttpException
           System.Web.HttpCompileException
           System.Web.HttpParseException
           System.Web.HttpRequestValidationException
           System.Web.HttpUnhandledException
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

HttpException コンストラクタ ()

HttpException クラスの新しいインスタンスを初期化し、空の HttpException オブジェクトを作成します。

名前空間: System.Web
アセンブリ: System.Web (system.web.dll 内)
構文構文

public HttpException ()
public:
HttpException ()
public HttpException ()
public function HttpException ()
解説解説
使用例使用例

HttpException クラスの HttpException コンストラクタのコード例を次に示します。CheckNumber メソッドは、ユーザーがテキスト ボックスに入力した値を受け取り、それが整数かどうかを確認します。値が整数でない場合、例外がスローされ、続いて新しい HttpException オブジェクトが作成され、スローされます。この例外は Button_Click イベント ハンドラでキャッチされ、エラー メッセージがブラウザに表示されます。

<html>
   <head>
      <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 MS_POSITIONING="GridLayout">
      <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>
<html>
   <head>
      <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 MS_POSITIONING="GridLayout">
      <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>
<html>
   <head>
        <script language="VJ#" runat="server">
            void CheckNumber() throws HttpException
            {
                try {
                    // Check whether the value is an integer.
                    String convertInt = textbox1.get_Text();
                    Convert.ToInt32(convertInt);
                }
                catch(Exception e) {
                    // Throw a 'HttpException' object.
                    throw new HttpException();
                }
            } //CheckNumber
          
            void Button_Click(Object sender, EventArgs e)
            {
                try {
                    CheckNumber();
                    label1.set_Text("The integer value you entered is: "
 
                        + textbox1.get_Text());
                }
                catch(HttpException exp)
                {
                    label1.set_Text("<font color='red'>An HttpException
 was raised!:"
                        + " The value entered in the textbox
 is not an " 
                        + "integer.</font>");
                }
            } //Button_Click

            void page_load(Object sender,EventArgs e)
            {
                label1.set_Text("");
            } //page_load
      </script>
   </head>
   
   <body MS_POSITIONING="GridLayout">
      <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 ID="Button1" 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>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HttpException クラス
HttpException メンバ
System.Web 名前空間
InnerException

HttpException コンストラクタ (Int32, String)

HTTP 応答ステータス コードとエラー メッセージを使用して、HttpException クラスの新しいインスタンスを初期化します。

名前空間: System.Web
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Sub New ( _
    httpCode As Integer, _
    message As String _
)
Dim httpCode As Integer
Dim message As String

Dim instance As New HttpException(httpCode,
 message)
public HttpException (
    int httpCode,
    string message
)
public:
HttpException (
    int httpCode, 
    String^ message
)
public HttpException (
    int httpCode, 
    String message
)
public function HttpException (
    httpCode : int, 
    message : String
)

パラメータ

httpCode

エラーに対応するクライアントに送信された HTTP 応答ステータス コード。

message

例外がスローされたときに、クライアントに表示するエラー メッセージ。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

HttpException コンストラクタ (SerializationInfo, StreamingContext)

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

シリアル化したデータを使用して、HttpException クラスの新しいインスタンスを初期化します。

名前空間: System.Web
アセンブリ: System.Web (system.web.dll 内)
構文構文

Protected Sub New ( _
    info As SerializationInfo, _
    context As StreamingContext _
)
Dim info As SerializationInfo
Dim context As StreamingContext

Dim instance As New HttpException(info,
 context)
protected HttpException (
    SerializationInfo info,
    StreamingContext context
)
protected:
HttpException (
    SerializationInfo^ info, 
    StreamingContext context
)
protected HttpException (
    SerializationInfo info, 
    StreamingContext context
)
protected function HttpException (
    info : SerializationInfo, 
    context : StreamingContext
)

パラメータ

info

スローされている例外に関するシリアル化済みオブジェクト データを保持している SerializationInfo。

context

転送元または転送先に関するコンテキスト情報を保持している StreamingContext。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

HttpException コンストラクタ (String, Int32)

エラー メッセージと例外コードを使用して、HttpException クラスの新しいインスタンスを初期化します。

名前空間: System.Web
アセンブリ: System.Web (system.web.dll 内)
構文構文

使用例使用例

HttpException クラスの HttpException コンストラクタのコード例を次に示します。ユーザー入力値が 0 の場合は HttpException 例外がスローされます。

If Num = 0 Then
   Throw New HttpException("No
 value entered", 100)
end if
   
if (Num == 0)
{
   throw new HttpException("No value entered", 100);
}
   
if (num == 0) {
    throw new HttpException("No value entered", 100);
}        
if(num == 0){
   throw new HttpException("No value entered", 100)
}
   
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

HttpException コンストラクタ (String)

指定したエラー メッセージを使用して、HttpException クラスの新しいインスタンスを初期化します。

名前空間: System.Web
アセンブリ: System.Web (system.web.dll 内)
構文構文

使用例使用例

HttpException クラスの HttpException コンストラクタのコード例を次に示します。ユーザー入力値が 0 の場合は HttpException がスローされます。

If Num = 0 Then
   Throw New HttpException("No
 value entered")
end if
   
if (Num == 0)
{
   throw new HttpException("No value entered");
}
   
if (num == 0) {
    throw new HttpException("No value entered");
}        
if(num == 0){
   throw new HttpException("No value entered")
}
   
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

HttpException コンストラクタ (Int32, String, Int32)

HTTP 応答ステータス コード、エラー メッセージ、および例外コードを使用して、HttpException クラスの新しいインスタンスを初期化します。

名前空間: System.Web
アセンブリ: System.Web (system.web.dll 内)
構文構文

使用例使用例

HttpException クラスの HttpException コンストラクタのコード例を次に示します。ユーザーが、ユーザー名と電子メール情報を所定のテキスト ボックスに入力します。空のテキスト ボックスがある場合、HttpException オブジェクトが作成され、スローされます。HttpException のエラー コードが GetHttpCode メソッドによって取得され、Web ページに表示されます。

<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>
<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>
<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>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

HttpException コンストラクタ

HttpException クラスの新しいインスタンスを初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
HttpException () HttpException クラスの新しいインスタンスを初期化し、空の HttpException オブジェクトを作成します。
HttpException (String) 指定したエラー メッセージを使用して、HttpException クラスの新しいインスタンスを初期化します。
HttpException (Int32, String) HTTP 応答ステータス コードとエラー メッセージを使用して、HttpException クラスの新しいインスタンスを初期化します。
HttpException (SerializationInfo, StreamingContext) シリアル化したデータを使用して、HttpException クラスの新しいインスタンスを初期化します。
HttpException (String, Exception) エラー メッセージと InnerException プロパティを使用して、HttpException クラスの新しいインスタンスを初期化します。
HttpException (String, Int32) エラー メッセージと例外コードを使用して、HttpException クラスの新しいインスタンスを初期化します。
HttpException (Int32, String, Exception) HTTP 応答ステータス コード、エラー メッセージ、および InnerException プロパティを使用して、HttpException クラスの新しいインスタンスを初期化します。
HttpException (Int32, String, Int32) HTTP 応答ステータス コード、エラー メッセージ、および例外コードを使用して、HttpException クラスの新しいインスタンスを初期化します。
参照参照

関連項目

HttpException クラス
HttpException メンバ
System.Web 名前空間
InnerException

HttpException コンストラクタ (String, Exception)

エラー メッセージと InnerException プロパティを使用して、HttpException クラスの新しいインスタンスを初期化します。

名前空間: System.Web
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Sub New ( _
    message As String, _
    innerException As Exception _
)
Dim message As String
Dim innerException As Exception

Dim instance As New HttpException(message,
 innerException)
public HttpException (
    string message,
    Exception innerException
)
public:
HttpException (
    String^ message, 
    Exception^ innerException
)
public HttpException (
    String message, 
    Exception innerException
)
public function HttpException (
    message : String, 
    innerException : Exception
)

パラメータ

message

例外がスローされたときに、クライアントに表示するエラー メッセージ。

innerException

存在する場合は、現在の例外をスローした InnerException。

解説解説
使用例使用例

HttpException クラスの HttpException コンストラクタのコード例を次に示します。CheckNumber メソッドは、ユーザーがテキスト ボックスに入力した値を受け取り、それが整数かどうかを確認します。値が整数でない場合、例外がスローされ、続いて catch ブロックで新しい HttpException オブジェクトが作成され、スローされます。この例外は Button_Click イベント ハンドラでキャッチされ、エラー メッセージがブラウザに表示されます。

<html>
   <head>
      <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 MS_POSITIONING="GridLayout">
      <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>

<html>
   <head>  
      <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 MS_POSITIONING="GridLayout">
      <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>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HttpException クラス
HttpException メンバ
System.Web 名前空間
InnerException

HttpException コンストラクタ (Int32, String, Exception)

HTTP 応答ステータス コード、エラー メッセージ、および InnerException プロパティを使用して、HttpException クラスの新しいインスタンスを初期化します。

名前空間: System.Web
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Sub New ( _
    httpCode As Integer, _
    message As String, _
    innerException As Exception _
)
Dim httpCode As Integer
Dim message As String
Dim innerException As Exception

Dim instance As New HttpException(httpCode,
 message, innerException)
public HttpException (
    int httpCode,
    string message,
    Exception innerException
)
public:
HttpException (
    int httpCode, 
    String^ message, 
    Exception^ innerException
)
public HttpException (
    int httpCode, 
    String message, 
    Exception innerException
)
public function HttpException (
    httpCode : int, 
    message : String, 
    innerException : Exception
)

パラメータ

httpCode

クライアントに表示する HTTP 応答ステータス コード。

message

例外がスローされたときに、クライアントに表示するエラー メッセージ。

innerException

存在する場合は、現在の例外をスローした InnerException。

解説解説
使用例使用例

HttpException クラスの HttpException コンストラクタのコード例を次に示します。CheckNumber メソッドは、ユーザーが入力した値を受け取り、それが整数かどうかを確認します。値が整数でない場合、例外がスローされ、HTTP 応答ステータス コード、例外のメッセージ、および内部例外 (ある場合) を含む新しい HttpException オブジェクトが作成されます。この例外は Button_Click イベント ハンドラでキャッチされ、エラー メッセージ、エラー コード、および内部例外が表示されます。

<%@ Import Namespace="System.Drawing"
 %>
<html>
   <head>
      <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 MS_POSITIONING="GridLayout">
      <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>
<%@ Import Namespace="System.Drawing" %>
<html>
   <head>
      <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 MS_POSITIONING="GridLayout">
      <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>
   <head>
    <script language="VJ#" runat="server">
        void CheckNumber() throws HttpException
        {
            try {
                // Check whether the value is an integer.
                String convertInt = textbox1.get_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);
            }
        } //CheckNumber
        
        void Button_Click(Object sender, EventArgs e)
        {
            try {
                CheckNumber();
                label1.set_Text("The integer value you entered is: " 
                    + textbox1.get_Text());
            }
            catch(HttpException exp) {
                // Display the exception thrown.
                label1.set_ForeColor(Color.get_Red());
                label1.set_Text("An HttpException was raised!: " 
                    + exp.get_Message());
                System.Exception myInnerException = exp.get_InnerException();
                
                // Display the inner exception.
                label2.set_Text("The InnerException is : " 
                    + myInnerException.GetType());
            }
        } //Button_Click
     
        void page_load(Object sender,EventArgs e)
        {
            label1.set_Text("");
            label2.set_Text("");
        } //page_load
      </script>
   </head>

   <body MS_POSITIONING="GridLayout">
      <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>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HttpException クラス
HttpException メンバ
System.Web 名前空間
InnerException

HttpException プロパティ


パブリック プロパティパブリック プロパティ

プロテクト プロパティプロテクト プロパティ
  名前 説明
プロテクト プロパティ HResult  特定の例外に割り当てられているコード化数値である HRESULT を取得または設定します。 ( Exception から継承されます。)
参照参照

関連項目

HttpException クラス
System.Web 名前空間

その他の技術情報

例外の処理とスロー

HttpException メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド CreateFromLastError Win32 API GetLastError() メソッドから返されるエラー コードに基づいて、新しい HttpException 例外を作成します。
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。)
パブリック メソッド GetBaseException  派生クラスでオーバーライドされた場合、それ以後に発生する 1 つ以上の例外の主要な原因である Exception を返します。 ( Exception から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。)
パブリック メソッド GetHtmlErrorMessage クライアントに返す HTML エラー メッセージを取得します。
パブリック メソッド GetHttpCode クライアントに返す HTTP 応答ステータス コードを取得します。
パブリック メソッド GetObjectData オーバーライドされます。 例外に関する情報を取得して、SerializationInfo オブジェクトに追加します。
パブリック メソッド GetType  現在のインスタンスのランタイム型を取得します。 ( Exception から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド ToString  現在の例外の文字列形式を作成して返します。 ( Exception から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

HttpException クラス
System.Web 名前空間

その他の技術情報

例外の処理とスロー

HttpException メンバ

HTTP 要求の処理中に発生した例外を説明します。

HttpException データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
プロテクト コンストラクタプロテクト コンストラクタ
パブリック プロパティパブリック プロパティ
プロテクト プロパティプロテクト プロパティ
  名前 説明
プロテクト プロパティ HResult  特定の例外に割り当てられているコード化数値である HRESULT を取得または設定します。(Exception から継承されます。)
パブリック メソッドパブリック メソッド
( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド CreateFromLastError Win32 API GetLastError() メソッドから返されるエラー コードに基づいて、新しい HttpException 例外を作成します。
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。)
パブリック メソッド GetBaseException  派生クラスでオーバーライドされた場合、それ以後に発生する 1 つ以上の例外の主要な原因である Exception を返します。 (Exception から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。)
パブリック メソッド GetHtmlErrorMessage クライアントに返す HTML エラー メッセージを取得します。
パブリック メソッド GetHttpCode クライアントに返す HTTP 応答ステータス コードを取得します。
パブリック メソッド GetObjectData オーバーライドされます。 例外に関する情報を取得して、SerializationInfo オブジェクトに追加します。
パブリック メソッド GetType  現在のインスタンスのランタイム型を取得します。 (Exception から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド ToString  現在の例外の文字列形式を作成して返します。 (Exception から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

HttpException クラス
System.Web 名前空間

その他の技術情報

例外の処理とスロー



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「HttpException」の関連用語

HttpExceptionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HttpExceptionのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS