diff --git a/Tank/Tank/FormArmoredCarCollection.cs b/Tank/Tank/FormArmoredCarCollection.cs index b611e74..7c6cd7a 100644 --- a/Tank/Tank/FormArmoredCarCollection.cs +++ b/Tank/Tank/FormArmoredCarCollection.cs @@ -55,21 +55,23 @@ namespace Tank return; } _logger.LogInformation("Начало попытки добавления объекта"); - - if ((obj + tank) != false) + try { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowTanks(); - _logger.LogInformation($"Добавлен объект {obj}"); + if ((obj + tank) != false) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowTanks(); + _logger.LogInformation($"Добавлен объект {obj}"); + } } - else + catch (TankStorageOverflowException ex) { - TankStorageOverflowException ex = new TankStorageOverflowException(); MessageBox.Show(ex.Message); MessageBox.Show("Не удалось добавить объект"); - _logger.LogWarning($"{ex.Message} в наборе {listBoxStorages.SelectedItem.ToString()}"); + _logger.LogWarning($"{ex.Message} "); } + } private void ButtonAddArmoredCar_Click(object sender, EventArgs e) { diff --git a/Tank/Tank/Generics/SetGeneric.cs b/Tank/Tank/Generics/SetGeneric.cs index 02cf88e..5126c3c 100644 --- a/Tank/Tank/Generics/SetGeneric.cs +++ b/Tank/Tank/Generics/SetGeneric.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tank.Exceptions; namespace Tank.Generics { @@ -29,10 +30,10 @@ namespace Tank.Generics public bool Insert(T tank, int position) { - if (position < 0 || position > _maxCount) - return false; + if (position < 0 || position >= _maxCount) + throw new TankNotFoundException(position); if (Count >= _maxCount) - return false; + throw new TankStorageOverflowException(_maxCount); _places.Insert(0, tank); return true; }