Исправил эксепшеоны

This commit is contained in:
ivans 2024-06-13 15:59:00 +04:00
parent f9a01c77fa
commit bd4c44628c

View File

@ -97,7 +97,7 @@ public class StorageCollection<T>
{ {
if (_storages.Count == 0) if (_storages.Count == 0)
{ {
throw new Exception("В хранилище отсутствуют коллекции для сохранения"); throw new InvalidDataException("В хранилище отсутствуют коллекции для сохранения");
} }
if (File.Exists(filename)) if (File.Exists(filename))
{ {
@ -146,18 +146,18 @@ public class StorageCollection<T>
{ {
if (!File.Exists(filename)) if (!File.Exists(filename))
{ {
throw new Exception("Файл не существует"); throw new FileNotFoundException("Файл не существует");
} }
using (StreamReader fs = File.OpenText(filename)) using (StreamReader fs = File.OpenText(filename))
{ {
string str = fs.ReadLine(); string str = fs.ReadLine();
if (str == null || str.Length == 0) if (str == null || str.Length == 0)
{ {
throw new Exception("В файле нет данных"); throw new InvalidDataException("В файле нет данных");
} }
if (!str.StartsWith(_collectionKey)) if (!str.StartsWith(_collectionKey))
{ {
throw new Exception("В файле неверные данные"); throw new InvalidDataException("В файле неверные данные");
} }
_storages.Clear(); _storages.Clear();
string strs = ""; string strs = "";
@ -173,7 +173,7 @@ public class StorageCollection<T>
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType); ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
if (collection == null) if (collection == null)
{ {
throw new Exception("Не удалось создать коллекцию"); throw new InvalidOperationException("Не удалось создать коллекцию");
} }
collection.MaxCount = Convert.ToInt32(record[2]); collection.MaxCount = Convert.ToInt32(record[2]);
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries); string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
@ -185,11 +185,11 @@ public class StorageCollection<T>
{ {
if (collection.Insert(seaplane) == -1) if (collection.Insert(seaplane) == -1)
{ {
throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]); throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]);
} }
} catch (CollectionOverflowException ex) } catch (CollectionOverflowException ex)
{ {
throw new Exception("Коллекция переполнена", ex); throw new CollectionOverflowException("Коллекция переполнена", ex);
} }
} }
} }