XmlException 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 XmlException 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| XmlException() |
初始化 |
| XmlException(String) |
使用指定的錯誤訊息,初始化 |
| XmlException(SerializationInfo, StreamingContext) |
已淘汰.
利用 和 |
| XmlException(String, Exception) |
初始化 |
| XmlException(String, Exception, Int32, Int32) |
初始化類別的新實例 |
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.
利用 和 XmlException 物件中的SerializationInfo資訊初始化該StreamingContext類別的新實例。
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);
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}")>]
new System.Xml.XmlException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Xml.XmlException
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
錯誤條件的描述。
適用於
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
該行位置指示錯誤發生的位置。