diff --git a/DoubleDeckerBus/DoubleDeckerBus/BusNotFoundExeption.cs b/DoubleDeckerBus/DoubleDeckerBus/BusNotFoundExeption.cs
new file mode 100644
index 0000000..3757dac
--- /dev/null
+++ b/DoubleDeckerBus/DoubleDeckerBus/BusNotFoundExeption.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DoubleDeckerBus
+{
+ [Serializable]
+ internal class BusNotFoundException : ApplicationException
+ {
+ public BusNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
+ public BusNotFoundException() : base() { }
+ public BusNotFoundException(string message) : base(message) { }
+ public BusNotFoundException(string message, Exception exception) : base(message, exception) { }
+ protected BusNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
+ }
+}
diff --git a/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs b/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs
index 5422fea..80a242e 100644
--- a/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs
+++ b/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs
@@ -86,15 +86,27 @@ namespace DoubleDeckerBus
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
- if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
+ try
{
- MessageBox.Show("Объект удален");
- pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
}
- else
+ catch (BusNotFoundException ex)
{
- MessageBox.Show("Не удалось удалить объект");
+ MessageBox.Show($"Ошибка удаления: {ex.Message}");
}
+ catch (Exception ex)
+ {
+ MessageBox.Show($"Неизветсная шибка: {ex.Message}");
+ }
+
}
private void ButtonShowStorage_Click(object sender, EventArgs e)
@@ -181,13 +193,14 @@ namespace DoubleDeckerBus
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
- if (_mapsCollection.SaveData(saveFileDialog.FileName))
+ try
{
+ _mapsCollection.SaveData(saveFileDialog.FileName);
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
- else
+ catch (Exception ex)
{
- MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
diff --git a/DoubleDeckerBus/DoubleDeckerBus/MapsCollection.cs b/DoubleDeckerBus/DoubleDeckerBus/MapsCollection.cs
index a5e9c61..a4ca902 100644
--- a/DoubleDeckerBus/DoubleDeckerBus/MapsCollection.cs
+++ b/DoubleDeckerBus/DoubleDeckerBus/MapsCollection.cs
@@ -48,7 +48,7 @@ namespace DoubleDeckerBus
}
- public bool SaveData(string filename)
+ public void SaveData(string filename)
{
if (File.Exists(filename))
{
@@ -62,14 +62,13 @@ namespace DoubleDeckerBus
sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
}
}
- return true;
}
- public bool LoadData(string filename)
+ public void LoadData(string filename)
{
if (!File.Exists(filename))
{
- return false;
+ throw new FileNotFoundException("Файл не найден");
}
string line;
using (StreamReader sw = new(filename))
@@ -77,7 +76,7 @@ namespace DoubleDeckerBus
line = sw.ReadLine();
if (line == null || !line.Contains("MapsCollection"))
{
- return false;
+ throw new FileFormatException("Формат данных в файле не совпадает");
}
_mapStorages.Clear();
@@ -99,8 +98,6 @@ namespace DoubleDeckerBus
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
line = sw.ReadLine();
}
-
- return true;
}
}
}
diff --git a/DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs b/DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs
index 870b6db..d27f58d 100644
--- a/DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs
+++ b/DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs
@@ -45,7 +45,10 @@ namespace DoubleDeckerBus
///
public int Insert(T bus, int position)
{
- if (position < 0 || position >= _maxCount || BusyPlaces == _maxCount) return -1;
+ if (position < 0 || position >= _maxCount)
+ {
+ throw new BusNotFoundException("Место указано неверно");
+ }
BusyPlaces++;
_places.Insert(position, bus);
@@ -58,7 +61,10 @@ namespace DoubleDeckerBus
///
public T Remove(int position)
{
- if (position < 0 || position >= _maxCount) return null;
+ if (position < 0 || position >= _maxCount)
+ {
+ throw new BusNotFoundException(position);
+ }
T savedBus = _places[position];
_places.RemoveAt(position);
return savedBus;
diff --git a/DoubleDeckerBus/DoubleDeckerBus/StorageOverflowException.cs b/DoubleDeckerBus/DoubleDeckerBus/StorageOverflowException.cs
new file mode 100644
index 0000000..1e6d319
--- /dev/null
+++ b/DoubleDeckerBus/DoubleDeckerBus/StorageOverflowException.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DoubleDeckerBus
+{
+ [Serializable]
+ internal class StorageOverflowException : ApplicationException
+ {
+ public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { }
+ public StorageOverflowException() : base() { }
+ public StorageOverflowException(string message) : base(message) { }
+ public StorageOverflowException(string message, Exception exception) : base(message, exception) { }
+ protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
+ }
+}