From 12cafe7ff5ecdd970b5555d08cde7f7ee01b1c9c Mon Sep 17 00:00:00 2001 From: Uwe Seimet Date: Wed, 25 Aug 2021 12:52:38 +0200 Subject: [PATCH] Updated error handling --- src/raspberrypi/devices/disk.cpp | 14 ++++++++------ src/raspberrypi/devices/disk.h | 2 +- src/raspberrypi/devices/sasihd.cpp | 7 +------ src/raspberrypi/devices/scsihd.cpp | 7 +------ 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/raspberrypi/devices/disk.cpp b/src/raspberrypi/devices/disk.cpp index 7eb502f9..538e92ab 100644 --- a/src/raspberrypi/devices/disk.cpp +++ b/src/raspberrypi/devices/disk.cpp @@ -20,6 +20,7 @@ #include "os.h" #include "xm6.h" #include "controllers/sasidev_ctrl.h" +#include "exceptions.h" #include "disk.h" #include @@ -1750,10 +1751,12 @@ int Disk::GetSectorSizeInBytes() const return disk.size ? 1 << disk.size : 0; } -bool Disk::SetSectorSizeInBytes(int size, bool sasi) +void Disk::SetSectorSizeInBytes(int size, bool sasi) { if (sasi && size != 256 && size != 1024) { - return false; + stringstream error; + error << "Invalid sector size of " << size << " bytes"; + throw io_exception(error.str()); } switch (size) { @@ -1778,12 +1781,11 @@ bool Disk::SetSectorSizeInBytes(int size, bool sasi) break; default: - assert(false); - disk.size = 9; + stringstream error; + error << "Invalid sector size of " << size << " bytes"; + throw io_exception(error.str()); break; } - - return true; } int Disk::GetSectorSize() const diff --git a/src/raspberrypi/devices/disk.h b/src/raspberrypi/devices/disk.h index dbf5933f..59f92f9e 100644 --- a/src/raspberrypi/devices/disk.h +++ b/src/raspberrypi/devices/disk.h @@ -124,7 +124,7 @@ public: int SelectCheck10(const DWORD *cdb); // SELECT(10) check int GetSectorSizeInBytes() const; - bool SetSectorSizeInBytes(int, bool); + void SetSectorSizeInBytes(int, bool); int GetSectorSize() const; bool IsSectorSizeConfigurable() const; vector GetSectorSizes() const; diff --git a/src/raspberrypi/devices/sasihd.cpp b/src/raspberrypi/devices/sasihd.cpp index f3200294..a7d80133 100644 --- a/src/raspberrypi/devices/sasihd.cpp +++ b/src/raspberrypi/devices/sasihd.cpp @@ -70,12 +70,7 @@ void SASIHD::Open(const Filepath& path) fio.Close(); // Sector size (default 256 bytes) and number of blocks - if (!SetSectorSizeInBytes(GetConfiguredSectorSize() ? GetConfiguredSectorSize() : 256, true)) { - stringstream error; - error << "Invalid sector size " << GetConfiguredSectorSize(); - throw io_exception(error.str()); - - } + SetSectorSizeInBytes(GetConfiguredSectorSize() ? GetConfiguredSectorSize() : 256, true); SetBlockCount((DWORD)(size >> GetSectorSize())); #if defined(REMOVE_FIXED_SASIHD_SIZE) diff --git a/src/raspberrypi/devices/scsihd.cpp b/src/raspberrypi/devices/scsihd.cpp index 176e7bc9..f240ee8d 100644 --- a/src/raspberrypi/devices/scsihd.cpp +++ b/src/raspberrypi/devices/scsihd.cpp @@ -71,12 +71,7 @@ void SCSIHD::Open(const Filepath& path) fio.Close(); // Sector size (default 512 bytes) and number of blocks - if (!SetSectorSizeInBytes(GetConfiguredSectorSize() ? GetConfiguredSectorSize() : 512, false)) { - stringstream error; - error << "Invalid sector size " << GetConfiguredSectorSize(); - throw io_exception(error.str()); - - } + SetSectorSizeInBytes(GetConfiguredSectorSize() ? GetConfiguredSectorSize() : 512, false); SetBlockCount((DWORD)(size >> GetSectorSize())); // File size must be a multiple of the sector size