Quote:
try
{
if (val > max || val < min)
throw new ArgumentOutOfRangeException("Значение не в заявленном диапазоне.");
}
catch (ArgumentOutOfRangeException e)
{
Console.WriteLine($"Ошибка: {e}");
}
That bit makes no sense. Throwing an exception just so you can catch it on the next line and write a message to the console wastes a lot of resources. Just use:
if (val > max || val < min)
Console.WriteLine("Ошибка: Значение не в заявленном диапазоне.");
But you'll still have the issue that your object is in an invalid state, and the caller has no way of knowing that. It would be better to validate the value before changing the state of your object:
public int Value
{
get { return val; }
set
{
if (value > max || value < min)
throw new ArgumentOutOfRangeException("Значение не в заявленном диапазоне.");
val = value;
}
}