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)

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()

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:

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)

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

public:
 XmlException(System::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.

XmlException(SerializationInfo, StreamingContext)

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);
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.

XmlException(String, Exception)

Initializes a new instance of the XmlException class.

public:
 XmlException(System::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.

XmlException(String, Exception, Int32, Int32)

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);
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