XmlException Constructors

Definition

Initializes a new instance of the XmlException class.

Overloads

XmlException()

Initializes a new instance of the XmlException class.

XmlException(String)

Initializes a new instance of the XmlException class with a specified error message.

XmlException(SerializationInfo, StreamingContext)
Obsolete.

Initializes a new instance of the XmlException class using the information in the SerializationInfo and StreamingContext objects.

XmlException(String, Exception)

Initializes a new instance of the XmlException class.

XmlException(String, Exception, Int32, Int32)

Initializes a new instance of the XmlException class with the specified message, inner exception, line number, and line position.

XmlException()

Source:
XmlException.cs
Source:
XmlException.cs
Source:
XmlException.cs

Initializes a new instance of the XmlException class.

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

Remarks

The XmlException is a generic XML-related error that is thrown if problems occur during XML processing. The following example throws an XML exception because the <contacts> end tag is misspelled:

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

Applies to

XmlException(String)

Source:
XmlException.cs
Source:
XmlException.cs
Source:
XmlException.cs

Initializes a new instance of the XmlException class with a specified error message.

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)

Parameters

message
String

The error description.

Applies to

XmlException(SerializationInfo, StreamingContext)

Source:
XmlException.cs
Source:
XmlException.cs
Source:
XmlException.cs

Caution

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

Initializes a new instance of the XmlException class using the information in the SerializationInfo and StreamingContext objects.

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)

Parameters

info
SerializationInfo

The SerializationInfo object containing all the properties of an XmlException.

context
StreamingContext

The StreamingContext object containing the context information.

Attributes

Applies to

XmlException(String, Exception)

Source:
XmlException.cs
Source:
XmlException.cs
Source:
XmlException.cs

Initializes a new instance of the XmlException class.

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)

Parameters

message
String

The description of the error condition.

innerException
Exception

The Exception that threw the XmlException, if any. This value can be null.

Applies to

XmlException(String, Exception, Int32, Int32)

Source:
XmlException.cs
Source:
XmlException.cs
Source:
XmlException.cs

Initializes a new instance of the XmlException class with the specified message, inner exception, line number, and line position.

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)

Parameters

message
String

The error description.

innerException
Exception

The exception that is the cause of the current exception. This value can be null.

lineNumber
Int32

The line number indicating where the error occurred.

linePosition
Int32

The line position indicating where the error occurred.

Applies to