From 5c23c8006617d344875b618ebcd0a438e09a9e4f Mon Sep 17 00:00:00 2001 From: platoff aeeee Date: Sun, 24 Dec 2023 22:57:08 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=207?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/Tank/FormArmoredCarCollection.cs | 18 ++++++++++-------- Tank/Tank/Generics/SetGeneric.cs | 7 ++++--- 2 files changed, 14 insertions(+), 11 deletions(-) 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; }