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) { } + } +} +