HttpParseException クラス

定義

解析エラーが発生したときにスローされる例外。

public ref class HttpParseException sealed : System::Web::HttpException
public sealed class HttpParseException : System.Web.HttpException
[System.Serializable]
public sealed class HttpParseException : System.Web.HttpException
type HttpParseException = class
    inherit HttpException
[<System.Serializable>]
type HttpParseException = class
    inherit HttpException
Public NotInheritable Class HttpParseException
Inherits HttpException
継承
属性

次の例では、ページ解析中に生成されたエラーを HttpParseException カスタマイズする方法を示します。 この例では、カスタマイズされたコントロールが定義されています HtmlSelect 。 カスタム コントロールの子要素が指定された型でない場合は、HttpParseExceptionカスタムHtmlSelectBuilderのオーバーライドされたGetChildControlTypeメソッドで an がスローされます。 解析例外を生成するには、子要素リテラル MyCustomOption を他の文字列に変更します。

<%@ Page Language="C#"%>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" Assembly="Samples.AspNet.CS" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>HttpParseException Example</title>
</head>
  <body>
    <form id="Form1" runat="server">
      <h3>HttpParseException Example</h3>

      <aspSample:CustomHtmlSelectWithHttpParseException
       id="customhtmlselect1"
       runat="server">
      <aspSample:MyCustomOption optionid="option1" value="1"/>
      <aspSample:MyCustomOption optionid="option2" value="2"/>
      <aspSample:MyCustomOption optionid="option3" value="3"/>
      </aspSample:CustomHtmlSelectWithHttpParseException>

    </form>

  </body>

</html>
<%@ Page Language="VB"%>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB" Assembly="Samples.AspNet.VB" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>HttpParseException Example</title>
</head>
  <body>
    <form id="Form1" runat="server">
      <h3>HttpParseException Example</h3>

      <aspSample:CustomHtmlSelectWithHttpParseException
       id="customhtmlselect1"
       runat="server">
      <aspSample:MyCustomOption optionid="option1" value="1"/>
      <aspSample:MyCustomOption optionid="option2" value="2"/>
      <aspSample:MyCustomOption optionid="option3" value="3"/>
      </aspSample:CustomHtmlSelectWithHttpParseException>

    </form>

  </body>

</html>
using System;
using System.Security.Permissions;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Samples.AspNet.CS
{
    // Define a child control for the custom HtmlSelect.
    public class MyCustomOption
    {
        string _id;
        string _value;

        public string optionid
        {
            get
            { return _id; }
            set
            { _id = value; }
        }

        public string value
        {
            get
            { return _value; }
            set
            { _value = value; }
        }
    }

    // Define a custom HtmlSelectBuilder.
    public class MyHtmlSelectBuilderWithparseException : HtmlSelectBuilder
    {
        [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
        public override Type GetChildControlType(string tagName, IDictionary attribs)
        {
            // Distinguish between two possible types of child controls.
            if (tagName.ToLower().EndsWith("mycustomoption"))
            {
                return typeof(MyCustomOption);
            }
            else
            {
                throw new HttpParseException("This custom HtmlSelect control" +                                                  "requires child elements of the form \"MyCustomOption\"");
            }
        }
    }

    [ControlBuilderAttribute(typeof(MyHtmlSelectBuilderWithparseException))]
    public class CustomHtmlSelectWithHttpParseException : HtmlSelect
    {
        // Override the AddParsedSubObject method.
        protected override void AddParsedSubObject(object obj)
        {

            string _outputtext;
            if (obj is MyCustomOption)
            {
                _outputtext = "custom select option : " + ((MyCustomOption)obj).value;
                ListItem li = new ListItem(_outputtext, ((MyCustomOption)obj).value);
                base.Items.Add(li);
            }
        }
    }
}
Imports System.Security.Permissions
Imports System.Collections
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

Namespace Samples.AspNet.VB
    ' Define a child control for the custom HtmlSelect.
    Public Class MyCustomOption
        Private _id As String
        Private _value As String


        Public Property optionid() As String
            Get
                Return _id
            End Get
            Set(ByVal value As String)
                _id = value
            End Set
        End Property

        Public Property value() As String
            Get
                Return _value
            End Get
            Set(ByVal value As String)
                _value = value
            End Set
        End Property
    End Class

    ' Define a custom HtmlSelectBuilder.
    Public Class MyHtmlSelectBuilderWithparseException
        Inherits HtmlSelectBuilder

        <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
        Public Overrides Function GetChildControlType(ByVal tagName As String, ByVal attribs As IDictionary) As Type

            ' Distinguish between two possible types of child controls.
            If tagName.ToLower().EndsWith("mycustomoption") Then

                Return GetType(MyCustomOption)

            Else
                
                Throw New HttpParseException("This custom HtmlSelect control" & _ 
                         "requires child elements of the form ""MyCustomOption""")
            End If

        End Function

    End Class


    <ControlBuilderAttribute(GetType(MyHtmlSelectBuilderWithparseException))> _
    Public Class CustomHtmlSelectWithHttpParseException
        Inherits HtmlSelect

        ' Override the AddParsedSubObject method.
        Protected Overrides Sub AddParsedSubObject(ByVal obj As Object)

            Dim _outputtext As String
            If TypeOf obj Is MyCustomOption Then
                _outputtext = "custom select option : " + CType(obj, MyCustomOption).value
                Dim li As New ListItem(_outputtext, CType(obj, MyCustomOption).value)
                MyBase.Items.Add(li)
            End If

        End Sub

    End Class

End Namespace

注釈

このHttpParseExceptionクラスは、ASP.NET がパーサー例外情報を出力できるようにする HTTP 固有の例外クラスです。 例外のスローと処理の詳細については、「 例外」を参照してください。

コンストラクター

HttpParseException()

HttpParseException クラスの新しいインスタンスを初期化します。

HttpParseException(String)

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

HttpParseException(String, Exception)

指定したエラー メッセージと内部例外に対する参照を使用して、HttpParseException クラスの新しいインスタンスを初期化します。

HttpParseException(String, Exception, String, String, Int32)

コンパイルされていたソース コードに関する情報と例外が発生した行番号を使用して、HttpParseException クラスの新しいインスタンスを初期化します。

プロパティ

Data

例外に関する追加のユーザー定義情報を提供する、キーと値のペアのコレクションを取得します。

(継承元 Exception)
ErrorCode

エラーの HRESULT を取得します。

(継承元 ExternalException)
FileName

エラーの発生時に解析されていたファイルの名前を取得します。

HelpLink

この例外に関連付けられているヘルプ ファイルへのリンクを取得または設定します。

(継承元 Exception)
HResult

特定の例外に割り当てられているコード化数値である HRESULT を取得または設定します。

(継承元 Exception)
InnerException

現在の例外の原因となる Exception インスタンスを取得します。

(継承元 Exception)
Line

エラーの発生時に解析されていた行の番号を取得します。

Message

現在の例外を説明するメッセージを取得します。

(継承元 Exception)
ParserErrors

現在の例外の解析エラーを取得します。

Source

エラーの原因となるアプリケーションまたはオブジェクトの名前を取得または設定します。

(継承元 Exception)
StackTrace

呼び出し履歴で直前のフレームの文字列形式を取得します。

(継承元 Exception)
TargetSite

現在の例外がスローされたメソッドを取得します。

(継承元 Exception)
VirtualPath

エラーを生成したソース ファイルへの仮想パスを取得します。

WebEventCode

HTTP 例外に関連付けられているイベント コードを取得します。

(継承元 HttpException)

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetBaseException()

派生クラスでオーバーライドされた場合、それ以後に発生する 1 つ以上の例外の根本原因である Exception を返します。

(継承元 Exception)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetHtmlErrorMessage()

クライアントに返す HTML エラー メッセージを取得します。

(継承元 HttpException)
GetHttpCode()

クライアントに返す HTTP 応答ステータス コードを取得します。

(継承元 HttpException)
GetObjectData(SerializationInfo, StreamingContext)

派生クラスでオーバーライドされた場合は、その例外に関する情報を使用して SerializationInfo オブジェクトを設定します。

GetObjectData(SerializationInfo, StreamingContext)

例外に関する情報を取得して、SerializationInfo オブジェクトに追加します。

(継承元 HttpException)
GetType()

現在のインスタンスのランタイム型を取得します。

(継承元 Exception)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

エラーの HRESULT が格納された文字列を返します。

(継承元 ExternalException)

events

SerializeObjectState
互換性のために残されています。

例外がシリアル化され、例外に関するシリアル化されたデータを含む例外状態オブジェクトが作成されたときに発生します。

(継承元 Exception)

適用対象

こちらもご覧ください