HttpParseException Kelas

Definisi

Pengecualian yang dilemparkan ketika terjadi kesalahan penguraian.

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
Warisan
Atribut

Contoh

Contoh berikut menunjukkan cara menggunakan untuk menyesuaikan kesalahan yang HttpParseException dihasilkan selama penguraian halaman. Dalam contoh ini, kontrol yang disesuaikan HtmlSelect ditentukan. Jika elemen turunan dari kontrol kustom bukan dari jenis tertentu, maka HttpParseException dilemparkan dalam metode yang ditimpa GetChildControlType dari kustom HtmlSelectBuilder. Untuk menghasilkan pengecualian penguraian, ubah elemen turunan secara harfiah MyCustomOption ke string lainnya.

<%@ 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

Keterangan

Kelas HttpParseException adalah kelas pengecualian khusus HTTP yang memungkinkan ASP.NET untuk menghasilkan informasi pengecualian pengurai output. Untuk informasi selengkapnya tentang pengecualian pelemparan dan penanganan, lihat Pengecualian.

Konstruktor

Nama Deskripsi
HttpParseException()

Menginisialisasi instans baru dari kelas HttpParseException.

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

Menginisialisasi instans HttpParseException baru kelas dengan informasi spesifik tentang kode sumber yang dikompilasi dan nomor baris tempat pengecualian terjadi.

HttpParseException(String, Exception)

Menginisialisasi instans HttpParseException baru kelas dengan pesan kesalahan tertentu dan referensi ke bagian dalam.

HttpParseException(String)

Menginisialisasi instans baru kelas HttpParseException dengan pesan kesalahan tertentu.

Properti

Nama Deskripsi
Data

Mendapatkan kumpulan pasangan kunci/nilai yang memberikan informasi tambahan yang ditentukan pengguna tentang pengecualian.

(Diperoleh dari Exception)
ErrorCode

HRESULT Mendapatkan kesalahan.

(Diperoleh dari ExternalException)
FileName

Mendapatkan nama file yang sedang diurai ketika kesalahan terjadi.

HelpLink

Mendapatkan atau mengatur tautan ke file bantuan yang terkait dengan pengecualian ini.

(Diperoleh dari Exception)
HResult

Mendapatkan atau mengatur HRESULT, nilai numerik berkode yang ditetapkan ke pengecualian tertentu.

(Diperoleh dari Exception)
InnerException

Mendapatkan instans Exception yang menyebabkan pengecualian saat ini.

(Diperoleh dari Exception)
Line

Mendapatkan jumlah baris yang diurai ketika kesalahan terjadi.

Message

Mendapatkan pesan yang menjelaskan pengecualian saat ini.

(Diperoleh dari Exception)
ParserErrors

Mendapatkan kesalahan pengurai untuk pengecualian saat ini.

Source

Mendapatkan atau mengatur nama aplikasi atau objek yang menyebabkan kesalahan.

(Diperoleh dari Exception)
StackTrace

Mendapatkan representasi string dari bingkai langsung pada tumpukan panggilan.

(Diperoleh dari Exception)
TargetSite

Mendapatkan metode yang melemparkan pengecualian saat ini.

(Diperoleh dari Exception)
VirtualPath

Mendapatkan jalur virtual ke file sumber yang menghasilkan kesalahan.

WebEventCode

Mendapatkan kode peristiwa yang terkait dengan pengecualian HTTP.

(Diperoleh dari HttpException)

Metode

Nama Deskripsi
Equals(Object)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
GetBaseException()

Ketika ditimpa di kelas turunan, mengembalikan Exception yang merupakan akar penyebab dari satu atau beberapa pengecualian berikutnya.

(Diperoleh dari Exception)
GetHashCode()

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetHtmlErrorMessage()

Mendapatkan pesan kesalahan HTML untuk kembali ke klien.

(Diperoleh dari HttpException)
GetHttpCode()

Mendapatkan kode status respons HTTP untuk kembali ke klien.

(Diperoleh dari HttpException)
GetObjectData(SerializationInfo, StreamingContext)

Saat ditimpa di kelas turunan, mengatur SerializationInfo objek dengan informasi tentang pengecualian.

GetType()

Mendapatkan jenis runtime instans saat ini.

(Diperoleh dari Exception)
MemberwiseClone()

Membuat salinan dangkal dari Objectsaat ini.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang berisi HRESULT kesalahan.

(Diperoleh dari ExternalException)

Acara

Nama Deskripsi
SerializeObjectState
Kedaluwarsa.

Terjadi ketika pengecualian diserialisasikan untuk membuat objek status pengecualian yang berisi data berseri tentang pengecualian.

(Diperoleh dari Exception)

Berlaku untuk

Lihat juga