ConfigurationParseException Class
Definition
- Namespace
- Bodu.Text.Configuration
- Assembly
- Bodu.Text.Configuration.dll
- Package
- Bodu.Text.Configuration 1.0.0
The exception raised when a configuration document cannot be parsed. Exposes the originating diagnostic ( Diagnostic) together with any additional diagnostics gathered before the failure.
public sealed class ConfigurationParseException : FormatException, ISerializable
- Inheritance
-
ConfigurationParseException
- Implements
- Inherited Members
- Extension Methods
Examples
try
{
IniDocument doc = ConfigurationDocument.Parse(text);
}
catch (ConfigurationParseException ex)
{
// The primary diagnostic includes a source location that points back into the document.
Console.WriteLine($"Parse failed at {ex.Location}: {ex.Message}");
// Every diagnostic gathered before the failure is preserved.
foreach (ConfigurationDiagnostic d in ex.Diagnostics)
Console.WriteLine($" {d}");
}
Remarks
In Throw mode the parser raises this exception on the first recoverable error it encounters. In Collect mode this exception is raised only for non-recoverable errors (such as a truncated stream); recoverable errors surface instead on the Diagnostics list.
The exception always provides a non-default Diagnostics array; when a single diagnostic triggered the failure it also appears as Diagnostic. Location forwards to the primary diagnostic's location and falls back to None when no diagnostic is attached.
Constructors
ConfigurationParseException()
Initializes a new instance of the ConfigurationParseException class with a default message.
public ConfigurationParseException()
ConfigurationParseException(ConfigurationDiagnostic)
Initializes a new instance of the ConfigurationParseException class from a single diagnostic. The diagnostic is exposed both via Diagnostic and as the single entry of Diagnostics.
public ConfigurationParseException(ConfigurationDiagnostic diagnostic)
Parameters
diagnosticConfigurationDiagnosticThe diagnostic that triggered the failure.
Exceptions
- ArgumentNullException
diagnosticis null.
ConfigurationParseException(IReadOnlyList<ConfigurationDiagnostic>)
Initializes a new instance of the ConfigurationParseException class from a set of previously collected diagnostics. The first entry, if any, is exposed via Diagnostic.
public ConfigurationParseException(IReadOnlyList<ConfigurationDiagnostic> diagnostics)
Parameters
diagnosticsIReadOnlyList<ConfigurationDiagnostic>The diagnostics gathered before the failure.
Exceptions
- ArgumentNullException
diagnosticsis null.
ConfigurationParseException(string)
Initializes a new instance of the ConfigurationParseException class with the specified message.
public ConfigurationParseException(string message)
Parameters
messagestringThe message describing the failure.
ConfigurationParseException(string, Exception?)
Initializes a new instance of the ConfigurationParseException class with the specified message and inner exception.
public ConfigurationParseException(string message, Exception? innerException)
Parameters
Properties
Diagnostic
Gets the primary diagnostic that triggered this exception, or null if the exception was constructed without one.
public ConfigurationDiagnostic? Diagnostic { get; }
Property Value
- ConfigurationDiagnostic
The primary diagnostic, or null.
Diagnostics
Gets the diagnostics gathered prior to the failure. Always returns a non-default array; may be empty.
public ImmutableArray<ConfigurationDiagnostic> Diagnostics { get; }
Property Value
- ImmutableArray<ConfigurationDiagnostic>
An immutable, possibly empty list of diagnostics.
Location
Gets the location in the source document that triggered the exception.
public ConfigurationSourceLocation Location { get; }
Property Value
- ConfigurationSourceLocation
The associated ConfigurationSourceLocation, or None when no primary diagnostic is available.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |