From fdde6661295f0af380ac69f90f6b60a44966bdf1 Mon Sep 17 00:00:00 2001 From: Tonb73 Date: Mon, 13 May 2024 10:05:42 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=BD=D0=B0=D1=81=D0=BB=D0=B5=D0=B4=D0=BD=D0=B8=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=20Exception?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StorageCollection.cs | 10 ++++----- .../Exceptions/EmptyFileException.cs | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 ProjectElectricLocomotive/Exceptions/EmptyFileException.cs diff --git a/ProjectElectricLocomotive/CollectionGenericObjects/StorageCollection.cs b/ProjectElectricLocomotive/CollectionGenericObjects/StorageCollection.cs index a1b60ba..6e6006e 100644 --- a/ProjectElectricLocomotive/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectElectricLocomotive/CollectionGenericObjects/StorageCollection.cs @@ -158,19 +158,19 @@ where T : DrawningLocomotive if (!File.Exists(filename)) { - throw new Exception("Файл не существует"); + throw new FileNotFoundException(filename); } using (StreamReader fs = File.OpenText(filename)) { string str = fs.ReadLine(); if (str == null || str.Length == 0) { - throw new Exception("В файле нет данных"); + throw new FileFormatException(filename); } if (!str.StartsWith(_collectionKey)) { - throw new Exception("В файле неверные данные"); + throw new FileFormatException(filename); } _storages.Clear(); string strs = ""; @@ -198,12 +198,12 @@ where T : DrawningLocomotive { if (collection.Insert(locomotive) == -1) { - throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]); + throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]); } } catch (CollectionOverflowException ex) { - throw new Exception("Коллекция переполнена", ex); + throw new CollectionOverflowException("Коллекция переполнена", ex); } } diff --git a/ProjectElectricLocomotive/Exceptions/EmptyFileException.cs b/ProjectElectricLocomotive/Exceptions/EmptyFileException.cs new file mode 100644 index 0000000..a69f655 --- /dev/null +++ b/ProjectElectricLocomotive/Exceptions/EmptyFileException.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectElectricLocomotive.Exceptions +{ + public class EmptyFileExeption : Exception + { + public EmptyFileExeption(string name) : base("Файл" + name + "пустой ") { } + public EmptyFileExeption() : base("В хранилище отсутствуют коллекции для сохранения") { } + public EmptyFileExeption(string name, string message) : base(message) { } + public EmptyFileExeption(string name, string message, Exception exception) : + base(message, exception) + { } + protected EmptyFileExeption(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} +