TomlFormatException Class
Definition
Represents an error that occurs when TOML data is malformed or violates the TOML specification.
public sealed class TomlFormatException : FormatException, ISerializable
- Inheritance
-
TomlFormatException
- Implements
- Inherited Members
- Extension Methods
Examples
try
{
ServerConfig config = TomlSerializer.Deserialize<ServerConfig>(payload);
}
catch (TomlFormatException ex)
{
Console.Error.WriteLine($"Malformed TOML at line {ex.LineNumber}, column {ex.ColumnNumber}: {ex.Message}");
}
Remarks
Raised by the TOML reader - and therefore surfaced by TomlSerializer while deserializing - when the source
text cannot be interpreted as a valid TOML document: for example, an unterminated string, an invalid escape
sequence, a duplicate key, a redefinition of a table, or an out-of-range integer. The error is signalled through the
FormatException hierarchy so callers can catch it alongside other parse failures.
Because TOML is a line-oriented format, the exception records its position as a LineNumber and ColumnNumber in addition to the absolute character Offset. Each is null when the error is not associated with a specific location.
Constructors
TomlFormatException()
Initializes a new instance of the TomlFormatException class.
public TomlFormatException()
TomlFormatException(string)
Initializes a new instance of the TomlFormatException class.
public TomlFormatException(string message)
Parameters
messagestringThe error message.
TomlFormatException(string, Exception)
Initializes a new instance of the TomlFormatException class.
public TomlFormatException(string message, Exception innerException)
Parameters
TomlFormatException(string, int, int, int)
Initializes a new instance of the TomlFormatException class and records the source location at which the parse error was detected.
public TomlFormatException(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 |