When I call ScriptureRangeParser.GetChapters(), I sometimes need to wrap it in a try/catch to ensure that any invalid chapter ranges (i.e. because a versification has changed) do not crash the method calling it, and I would rather the method just skip the range.
Does it make sense to have a ScriptureRangeParser.TryGetChapters(string scriptureRange, out Dictionary<string, List<int>> chapters) method that returns true if the chapters were retrieved, or false if they were not?
Another option could be to have a more forgiving GetChapters() implementation that will just parse the chapter ranges specified, even if they are not precisely the same as the versification requires (i.e. additional chapter numbers are in the range)
In Scripture Forge I created an extension method along the lines of:
public static bool TryGetChapters(
this ScriptureRangeParser scriptureRangeParser,
string chapterSelections,
[NotNullWhen(true)] out Dictionary<string, List<int>>? chapters
)
{
try
{
chapters = scriptureRangeParser.GetChapters(chapterSelections);
return true;
}
catch (ArgumentException)
{
chapters = null;
return false;
}
}
When I call
ScriptureRangeParser.GetChapters(), I sometimes need to wrap it in a try/catch to ensure that any invalid chapter ranges (i.e. because a versification has changed) do not crash the method calling it, and I would rather the method just skip the range.Does it make sense to have a
ScriptureRangeParser.TryGetChapters(string scriptureRange, out Dictionary<string, List<int>> chapters)method that returnstrueif the chapters were retrieved, orfalseif they were not?Another option could be to have a more forgiving GetChapters() implementation that will just parse the chapter ranges specified, even if they are not precisely the same as the versification requires (i.e. additional chapter numbers are in the range)
In Scripture Forge I created an extension method along the lines of: