More exception tidying

This commit is contained in:
Adrian Conlon 2024-09-14 10:03:49 +01:00
parent da56e79784
commit ee0fd13ad5
2 changed files with 10 additions and 18 deletions

View File

@ -57,10 +57,7 @@
public void AddLabel(Symbol symbol) public void AddLabel(Symbol symbol)
{ {
if (symbol.Type != "lab") ArgumentOutOfRangeException.ThrowIfNotEqual("lab", symbol.Type, nameof(symbol));
{
throw new ArgumentOutOfRangeException(nameof(symbol), symbol, "Not a label");
}
this.Labels.Add(symbol); this.Labels.Add(symbol);
this.AddAddress(symbol); this.AddAddress(symbol);
} }
@ -108,10 +105,7 @@
public void AddEquate(Symbol symbol) public void AddEquate(Symbol symbol)
{ {
if (symbol.Type != "equ") ArgumentOutOfRangeException.ThrowIfNotEqual("equ", symbol.Type, nameof(symbol));
{
throw new ArgumentOutOfRangeException(nameof(symbol), symbol, "Not an equate");
}
this.Equates.Add(symbol); this.Equates.Add(symbol);
this.AddConstant(symbol); this.AddConstant(symbol);
} }
@ -315,7 +309,7 @@
if (!this._parsed.TryGetValue(key, out var parsed)) if (!this._parsed.TryGetValue(key, out var parsed))
{ {
throw new InvalidOperationException($"Debugging section: '{key}' is unavailable"); throw new ArgumentOutOfRangeException(nameof(key), key, "Debugging section is unavailable");
} }
Debug.Assert(into.Count == 0); Debug.Assert(into.Count == 0);
@ -409,11 +403,8 @@
private void ParseLine(string[] elements) private void ParseLine(string[] elements)
{ {
Debug.Assert(elements != null); ArgumentNullException.ThrowIfNull(elements, nameof(elements));
if (elements.Length != 2) ArgumentOutOfRangeException.ThrowIfNotEqual(elements.Length, 2, nameof(elements));
{
throw new InvalidOperationException("Invalid symbol file format (definition does not have section/values format)");
}
var key = elements[0]; var key = elements[0];
var parts = elements[1].Split(','); var parts = elements[1].Split(',');

View File

@ -95,10 +95,10 @@
protected string? MaybeTakeString(string key) => this._strings.TryGetValue(key, out var value) ? value : null; protected string? MaybeTakeString(string key) => this._strings.TryGetValue(key, out var value) ? value : null;
protected List<int>? MaybeTakeMultiple(string key) => this._multiples.TryGetValue(key, out var value) ? value : null; protected List<int>? MaybeTakeMultiple(string key) => this._multiples.TryGetValue(key, out var value) ? value : null;
protected int TakeInteger(string key) => this.MaybeTakeInteger(key) ?? throw new InvalidOperationException($"Section is missing an integer entry named {key}"); protected int TakeInteger(string key) => this.MaybeTakeInteger(key) ?? throw new ArgumentOutOfRangeException(nameof(key), key, "Missing integer entry in section");
protected long TakeLong(string key) => this.MaybeTakeLong(key) ?? throw new InvalidOperationException($"Section is missing a long integer entry named {key}"); protected long TakeLong(string key) => this.MaybeTakeLong(key) ?? throw new ArgumentOutOfRangeException(nameof(key), key, "Missing long integer entry in section");
protected string TakeString(string key) => this.MaybeTakeString(key) ?? throw new InvalidOperationException($"Section is missing a string entry named {key}"); protected string TakeString(string key) => this.MaybeTakeString(key) ?? throw new ArgumentOutOfRangeException(nameof(key), key, "Missing string entry in section");
protected List<int> TakeMultiple(string key) => this.MaybeTakeMultiple(key) ?? throw new InvalidOperationException($"Section is missing a multiple entry named {key}"); protected List<int> TakeMultiple(string key) => this.MaybeTakeMultiple(key) ?? throw new ArgumentOutOfRangeException(nameof(key), key, "Missing multiple entry in section");
protected static string ExtractString(string value) => value.Trim('"'); protected static string ExtractString(string value) => value.Trim('"');
protected static string ExtractEnumeration(string value) => value; protected static string ExtractEnumeration(string value) => value;
@ -111,6 +111,7 @@
protected static int ExtractInteger(string value) => ExtractNumericValue<int>(value); protected static int ExtractInteger(string value) => ExtractNumericValue<int>(value);
protected static long ExtractLong(string value) => ExtractNumericValue<long>(value); protected static long ExtractLong(string value) => ExtractNumericValue<long>(value);
protected static List<string> ExtractCompoundString(string value) => new(value.Split('+')); protected static List<string> ExtractCompoundString(string value) => new(value.Split('+'));
protected static List<int> ExtractCompoundInteger(string value) protected static List<int> ExtractCompoundInteger(string value)
{ {
var elements = ExtractCompoundString(value); var elements = ExtractCompoundString(value);