PkmnLib.NET/PkmnLib.Static/Utils/Errors/OutOfRangeException.cs

25 lines
697 B
C#
Raw Normal View History

2024-07-20 11:51:52 +00:00
namespace PkmnLib.Static.Utils.Errors;
2024-07-20 14:12:39 +00:00
/// <summary>
/// A result that indicates an index is out of range.
/// </summary>
2024-07-28 10:52:17 +00:00
public class OutOfRangeException : Exception
2024-07-20 11:51:52 +00:00
{
2024-07-28 10:57:01 +00:00
private readonly string _hint;
private readonly int _index;
private readonly int _max;
2024-07-28 10:52:17 +00:00
/// <inheritdoc cref="OutOfRangeException"/>
public OutOfRangeException(string hint, int index, int max)
2024-07-20 11:51:52 +00:00
{
2024-07-28 10:57:01 +00:00
_hint = hint;
_index = index;
_max = max;
2024-07-20 11:51:52 +00:00
}
2024-07-28 10:57:01 +00:00
/// <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}.";
2024-07-20 11:51:52 +00:00
}