Table of Contents

DotEnvFormatException Class

Definition

Namespace
Bodu.Text.DotEnv
Assembly
Bodu.Text.DotEnv.dll
Package
Bodu.Text.DotEnv 1.3.0
Source
DotEnvFormatException.cs

Represents an error that occurs when DotEnv data is malformed.

public sealed class DotEnvFormatException : FormatException, ISerializable
Inheritance
DotEnvFormatException
Implements
Inherited Members
Extension Methods

Remarks

Raised by the DotEnv reader - and therefore surfaced by DotEnvSerializer while deserializing - when the source text cannot be interpreted as a valid DotEnv document: for example, an invalid key name, a missing assignment, or an unterminated quoted value. The error is signaled through the FormatException hierarchy so callers can catch it alongside other parse failures.

Because DotEnv is a line-oriented format, the exception records its position as a LineNumber and a byte ColumnNumber in addition to the absolute byte Offset. The reader sets all three to one position: the byte at which it found the error, or the opening quote of an unterminated quoted value. Each is null when the error is not associated with a specific location.

Constructors

DotEnvFormatException()

Initializes a new instance of the DotEnvFormatException class.

public DotEnvFormatException()

DotEnvFormatException(string)

Initializes a new instance of the DotEnvFormatException class.

public DotEnvFormatException(string message)

Parameters

message string

The error message.

DotEnvFormatException(string, Exception)

Initializes a new instance of the DotEnvFormatException class.

public DotEnvFormatException(string message, Exception innerException)

Parameters

message string

The error message.

innerException Exception

The inner exception.

DotEnvFormatException(string, int, int, int)

Initializes a new instance of the DotEnvFormatException class and records the source location at which the parse error was detected.

public DotEnvFormatException(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 within the line, counted in bytes, 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, counted in bytes from the start of 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.

Remarks

The column counts UTF-8 bytes, as Offset does, not decoded characters, so a character outside ASCII earlier on the line counts as its two to four bytes. A byte-order mark at the start of the source is counted by Offset but not by the column.

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.

Remarks

A line ends at a LF, a CR LF pair or a lone CR, inside a double-quoted value as well as between entries.

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