diff --git a/src/main/java/FileFormatException.java b/src/main/java/FileFormatException.java new file mode 100644 index 0000000..035761b --- /dev/null +++ b/src/main/java/FileFormatException.java @@ -0,0 +1,18 @@ +import java.io.IOException; + +public class FileFormatException extends IOException { + public FileFormatException() { + } + + public FileFormatException(String message) { + super(message); + } + + public FileFormatException(String message, Throwable cause) { + super(message, cause); + } + + public FileFormatException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/MapsCollection.java b/src/main/java/MapsCollection.java index da96dac..6eb9c19 100644 --- a/src/main/java/MapsCollection.java +++ b/src/main/java/MapsCollection.java @@ -67,14 +67,14 @@ public class MapsCollection { } } - public void LoadData(String filename) throws Exception { + public void LoadData(String filename) throws IOException { File f = new File(filename); if (!f.exists()) { throw new FileNotFoundException("Файл не найден"); } try (BufferedReader reader = new BufferedReader(new FileReader(filename))) { if (!reader.readLine().contains("MapsCollection")) - throw new Exception("Формат данных в файле не правильный"); + throw new FileFormatException("Формат данных в файле не правильный"); String line; while ((line = reader.readLine()) != null) { var elem = line.split(String.valueOf(separatorDict), -1); @@ -93,8 +93,6 @@ public class MapsCollection { _mapStorages.put(elem[0], new MapWithSetArmoredCarsGeneric<>(_pictureWidth, _pictureHeight, map)); _mapStorages.get(elem[0]).LoadData(elem[2].split(String.valueOf(separatorData))); } - } catch (IOException e) { - e.printStackTrace(); } } @@ -119,14 +117,14 @@ public class MapsCollection { } } - public void LoadDataMap(String filename) throws Exception{ + public void LoadDataMap(String filename) throws IOException{ File f = new File(filename); if (!f.exists()) { throw new FileNotFoundException("Файл не найден"); } try (BufferedReader reader = new BufferedReader(new FileReader(filename))) { if (!reader.readLine().contains("One Map")) - throw new Exception("Формат данных в файле не правильный"); + throw new FileFormatException("Формат данных в файле не правильный"); String line = reader.readLine(); var elem = line.split(String.valueOf(separatorDict), -1); AbstractMap map = null; @@ -147,8 +145,6 @@ public class MapsCollection { else _mapStorages.put(elem[0], new MapWithSetArmoredCarsGeneric<>(_pictureWidth, _pictureHeight, map)); _mapStorages.get(elem[0]).LoadData(elem[2].split(String.valueOf(separatorData))); - } catch (IOException e) { - e.printStackTrace(); } } }