Table of Contents

TomlFormatException Class

Definition

Namespace
Bodu.Text.Toml
Assembly
Bodu.Text.Toml.dll
Package
Bodu.Text.Toml 1.0.0
Source
TomlFormatException.cs

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

message string

The error message.

TomlFormatException(string, Exception)

Initializes a new instance of the TomlFormatException class.

public TomlFormatException(string message, Exception innerException)

Parameters

message string

The error message.

innerException Exception

The inner exception.

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

message string

The error message.

line int

The 1-based line number at which the error occurred.

column int

The 1-based column number within the line at which the error occurred.

offset int

The zero-based byte offset from the start of the source.

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

int?

The column number, or null when no column is associated with the error.

LineNumber

Gets the 1-based line number at which the parse error was detected, when available.

public int? LineNumber { get; }

Property Value

int?

The line number, or null when no line is associated with the error.

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

int?

The byte offset, or null when no position is associated with the error.

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

ProductVersions
.NET8, 10