SharpYaml throws YamlException for parsing and (most) serialization failures.
When possible, exceptions include:
YamlSerializerOptions.SourceNameThese are available through YamlException.SourceName, YamlException.Start, and YamlException.End.
var options = new YamlSerializerOptions
{
SourceName = "appsettings.yaml",
};
var model = YamlSerializer.Deserialize<MyConfig>(": invalid", options);
If you prefer failure-tolerant parsing without exceptions, use YamlSerializer.TryDeserialize(...):
if (!YamlSerializer.TryDeserialize<MyConfig>(yaml, out var model, options))
{
// Invalid YAML or incompatible payload.
}
If a required member is missing (for example [YamlRequired] or [JsonRequired]), deserialization throws YamlException.