YamlFormatException Class
Definition
Represents an error that occurs when YAML data is malformed or violates the YAML specification.
public sealed class YamlFormatException : FormatException, ISerializable
- Inheritance
-
YamlFormatException
- Implements
- Inherited Members
- Extension Methods
Remarks
Raised by the YAML reader - and therefore surfaced by YamlSerializer while deserializing - when the source
text cannot be interpreted as a valid YAML stream: for example, inconsistent indentation, a tab used for
indentation, an unterminated quoted scalar, an invalid escape sequence, a duplicate mapping key, or an alias that
refers to no anchor. The error is signalled through the FormatException hierarchy so callers can
catch it alongside other parse failures.
Because YAML is a line-oriented format, the exception records its position as a LineNumber and ColumnNumber in addition to the absolute byte Offset. Each is null when the error is not associated with a specific location.
Constructors
YamlFormatException()
Initializes a new instance of the YamlFormatException class.
public YamlFormatException()
YamlFormatException(string)
Initializes a new instance of the YamlFormatException class.
public YamlFormatException(string message)
Parameters
messagestringThe error message.
YamlFormatException(string, Exception)
Initializes a new instance of the YamlFormatException class.
public YamlFormatException(string message, Exception innerException)
Parameters
YamlFormatException(string, int, int, int)
Initializes a new instance of the YamlFormatException class and records the source location at which the parse error was detected.
public YamlFormatException(string message, int line, int column, int offset)
Parameters
Properties
ColumnNumber
Gets the 1-based column number within the line at which the parse error was detected, when available.
public int? ColumnNumber { get; }
Property Value
LineNumber
Gets the 1-based line number at which the parse error was detected, when available.
public int? LineNumber { get; }
Property Value
Offset
Gets the zero-based byte offset from the start of the UTF-8 source at which the parse error was detected, when available.
public int? Offset { get; }
Property Value
Remarks
The offset and ColumnNumber count UTF-8 bytes of the source document, not decoded characters; for ASCII-only documents the two coincide.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |