From 55bb9dd042f8d64361be5d6bd8975ed8fd600ae9 Mon Sep 17 00:00:00 2001
From: Kirill <117719052+KirillFirsof@users.noreply.github.com>
Date: Tue, 26 Dec 2023 21:33:04 +0400
Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D0=B5=D1=86=207=D0=BE=D0=B9?=
=?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D1=8B2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../RPP_FirstLaba_Tractor/SetGeneric.cs | 17 +++++++++--------
.../TractorsGenericStorage.cs | 6 +++---
2 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs
index 37df499..d3f8a13 100644
--- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs
+++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using ProjectTractor.Exceptions;
namespace ProjectTractor.Generics
{
@@ -38,7 +39,7 @@ namespace ProjectTractor.Generics
public bool Insert(T tractor)
{
if (_places.Count == _maxCount)
- return false;
+ throw new StorageOverflowException(_maxCount);
Insert(tractor, 0);
return true;
}
@@ -48,24 +49,24 @@ namespace ProjectTractor.Generics
/// Добавляемый автомобиль
/// Позиция
///
- public bool Insert(T tractor, int position)
+ public void Insert(T tractor, int position)
{
- if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
- return false;
+ if (_places.Count == _maxCount)
+ throw new StorageOverflowException(_maxCount);
+ if (!(position >= 0 && position <= Count))
+ throw new Exception("Неверная позиция для вставки");
_places.Insert(position, tractor);
- return true;
}
///
/// Удаление объекта из набора с конкретной позиции
///
///
///
- public bool Remove(int position)
+ public void Remove(int position)
{
if (!(position >= 0 && position < Count))
- return false;
+ throw new TractorNotFoundException(position);
_places.RemoveAt(position);
- return true;
}
///
/// Получение объекта из набора по позиции
diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs
index 778563b..162d731 100644
--- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs
+++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericStorage.cs
@@ -139,12 +139,12 @@ namespace ProjectTractor
string[] strings = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
if (strings == null || strings.Length == 0)
{
- throw new Exception("Нет данных для загрузки");
+ throw new IOException("Нет данных для загрузки");
}
if (!strings[0].StartsWith("TractorStorage"))
{
//если нет такой записи, то это не те данные
- throw new Exception("Неверный формат данных");
+ throw new IOException("Неверный формат данных");
}
_tractorStorages.Clear();
do
@@ -164,7 +164,7 @@ namespace ProjectTractor
{
if (!(collection + tractor))
{
- throw new Exception("Ошибка добавления в коллекцию");
+ throw new ArgumentNullException("Ошибка добавления в коллекцию");
}
}
}