Improve OutOfRangeException message
This commit is contained in:
parent
10f411f076
commit
3d5fb1a818
|
@ -6,9 +6,20 @@ namespace PkmnLib.Static.Utils.Errors;
|
|||
/// </summary>
|
||||
public class OutOfRangeException : Exception
|
||||
{
|
||||
private readonly string _hint;
|
||||
private readonly int _index;
|
||||
private readonly int _max;
|
||||
|
||||
/// <inheritdoc cref="OutOfRangeException"/>
|
||||
public OutOfRangeException(string hint, int index, int max)
|
||||
: base($"{hint} index {index} is out of range. Must be between 0 and {max - 1}.")
|
||||
{
|
||||
_hint = hint;
|
||||
_index = index;
|
||||
_max = max;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Message => _max == 0
|
||||
? $"{_hint} index {_index} is out of range. Collection is empty."
|
||||
: $"{_hint} index {_index} is out of range. Must be between 0 and {_max - 1}.";
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>12</LangVersion>
|
||||
<WarningsAsErrors>nullable</WarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
Loading…
Reference in New Issue