XmlException 建構函式

定義

初始化 XmlException 類別的新執行個體。

多載

XmlException()

初始化 XmlException 類別的新執行個體。

XmlException(String)

使用指定的錯誤訊息,初始化 XmlException 類別的新執行個體。

XmlException(SerializationInfo, StreamingContext)
已淘汰.

使用 SerializationInfoStreamingContext 物件中的資訊,初始化 XmlException 類別的新執行個體。

XmlException(String, Exception)

初始化 XmlException 類別的新執行個體。

XmlException(String, Exception, Int32, Int32)

使用指定的訊息、內部例外狀況、行號和行位置,初始化 XmlException 類別的新執行個體。

XmlException()

初始化 XmlException 類別的新執行個體。

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

備註

XmlException是一般 XML 相關錯誤,如果 XML 處理期間發生問題,就會擲回。 下列範例會擲回 XML 例外狀況, < 因為連絡人 > 結束標籤拼錯:

using System;
using System.Xml.Linq;

try
{
    XElement contacts = XElement.Parse(
        @"<Contacts>
            <Contact>
                <Name>Jim Wilson</Name>
            </Contact>
          </Contcts>");
    Console.WriteLine(contacts);
}
catch (System.Xml.XmlException e)
{
    Console.WriteLine(e.Message);
}
Try
    Dim contacts As XElement = XElement.Parse(
        "<Contacts>  
            <Contact>  
                <Name>Jim Wilson</Name>  
            </Contact>  
         </Contcts>")
    Console.WriteLine(contacts)
Catch e As System.Xml.XmlException
    Console.WriteLine(e.Message)
End Try

適用於

XmlException(String)

使用指定的錯誤訊息,初始化 XmlException 類別的新執行個體。

public:
 XmlException(System::String ^ message);
public XmlException (string message);
public XmlException (string? message);
new System.Xml.XmlException : string -> System.Xml.XmlException
Public Sub New (message As String)

參數

message
String

錯誤描述。

適用於

XmlException(SerializationInfo, StreamingContext)

警告

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

使用 SerializationInfoStreamingContext 物件中的資訊,初始化 XmlException 類別的新執行個體。

protected:
 XmlException(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected XmlException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected XmlException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new System.Xml.XmlException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Xml.XmlException
[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Xml.XmlException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Xml.XmlException
Protected Sub New (info As SerializationInfo, context As StreamingContext)

參數

info
SerializationInfo

SerializationInfo 物件包含 XmlException 所有的屬性。

context
StreamingContext

包含內容資訊的 StreamingContext 物件。

屬性

適用於

XmlException(String, Exception)

初始化 XmlException 類別的新執行個體。

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

參數

message
String

錯誤條件的描述。

innerException
Exception

擲回 ExceptionXmlException (如果有的話)。 這個值可以是 null

適用於

XmlException(String, Exception, Int32, Int32)

使用指定的訊息、內部例外狀況、行號和行位置,初始化 XmlException 類別的新執行個體。

public:
 XmlException(System::String ^ message, Exception ^ innerException, int lineNumber, int linePosition);
public XmlException (string message, Exception innerException, int lineNumber, int linePosition);
public XmlException (string? message, Exception? innerException, int lineNumber, int linePosition);
new System.Xml.XmlException : string * Exception * int * int -> System.Xml.XmlException
Public Sub New (message As String, innerException As Exception, lineNumber As Integer, linePosition As Integer)

參數

message
String

錯誤描述。

innerException
Exception

做為目前例外狀況發生原因的例外狀況。 這個值可以是 null

lineNumber
Int32

指示發生錯誤之位置的行號。

linePosition
Int32

指示發生錯誤之位置的行位置。

適用於