| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: MIT | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <stdexcept> | ||
| 8 | #include <string> | ||
| 9 | |||
| 10 | #include "types.h" | ||
| 11 | |||
| 12 | namespace imgdoc2 | ||
| 13 | { | ||
| 14 | /// Base class for all imgdoc2-specific exceptions. | ||
| 15 | class imgdoc2_exception : public std::runtime_error | ||
| 16 | { | ||
| 17 | public: | ||
| 18 | /// Constructor. | ||
| 19 | /// \param error_message Message describing the error. | ||
| 20 | 148 | explicit imgdoc2_exception(const char* error_message) | |
| 21 | 148 | : std::runtime_error(error_message) | |
| 22 | 148 | {} | |
| 23 | }; | ||
| 24 | |||
| 25 | /// Exception for signalling database errors. | ||
| 26 | class database_exception : public imgdoc2_exception | ||
| 27 | { | ||
| 28 | private: | ||
| 29 | int sqlite_errorcode_; | ||
| 30 | bool sqlite_errorcode_valid_; | ||
| 31 | public: | ||
| 32 | database_exception() = delete; | ||
| 33 | |||
| 34 | /// Constructor. | ||
| 35 | /// \param error_message Message describing the error. | ||
| 36 | 20 | explicit database_exception(const char* error_message) | |
| 37 | 20 | : imgdoc2_exception(error_message), sqlite_errorcode_(-1), sqlite_errorcode_valid_(false) | |
| 38 | 20 | {} | |
| 39 | |||
| 40 | /// Constructor. | ||
| 41 | /// \param error_message Message describing the error. | ||
| 42 | /// \param sqlite_error_code The SQLite error code. | ||
| 43 | ✗ | explicit database_exception(const char* error_message, int sqlite_error_code) | |
| 44 | ✗ | : imgdoc2_exception(error_message), sqlite_errorcode_(sqlite_error_code), sqlite_errorcode_valid_(true) | |
| 45 | ✗ | {} | |
| 46 | |||
| 47 | /// Gets a boolean indicating whether the SQLite error code is valid. | ||
| 48 | /// \returns True if the SQLite error code is valid; false otherwise. | ||
| 49 | ✗ | bool GetIsSqliteErrorCodeValid() const { return this->sqlite_errorcode_valid_; } | |
| 50 | |||
| 51 | /// Gets the SQLite error code. Call database_exception::GetIsSqliteErrorCodeValid() in order to test whether the error code is valid. | ||
| 52 | /// \returns The sqlite error code. | ||
| 53 | ✗ | int GetSqliteErrorCode() const { return this->sqlite_errorcode_; } | |
| 54 | |||
| 55 | /// Gets the SQLite provided error message for the error code. The result is unspecified if the error code is not valid. | ||
| 56 | /// \returns The SQLite provided error message. | ||
| 57 | std::string GetSqliteErrorMessage() const; | ||
| 58 | }; | ||
| 59 | |||
| 60 | /// Exception for signalling that an operation is not allowed in the current state. | ||
| 61 | class invalid_operation_exception : public imgdoc2_exception | ||
| 62 | { | ||
| 63 | public: | ||
| 64 | /// Constructor. | ||
| 65 | /// \param error_message Message describing the error. | ||
| 66 | ✗ | explicit invalid_operation_exception(const char* error_message) | |
| 67 | ✗ | : imgdoc2_exception(error_message) | |
| 68 | ✗ | {} | |
| 69 | }; | ||
| 70 | |||
| 71 | /// Exception for signalling logical errors during database-discovery. | ||
| 72 | class discovery_exception : public imgdoc2_exception | ||
| 73 | { | ||
| 74 | public: | ||
| 75 | /// Constructor. | ||
| 76 | /// \param error_message Message describing the error. | ||
| 77 | 2 | explicit discovery_exception(const char* error_message) | |
| 78 | 2 | : imgdoc2_exception(error_message) | |
| 79 | 2 | {} | |
| 80 | |||
| 81 | /// Constructor. | ||
| 82 | /// \param error_message Message describing the error. | ||
| 83 | ✗ | explicit discovery_exception(const std::string& error_message) | |
| 84 | ✗ | : discovery_exception(error_message.c_str()) | |
| 85 | ✗ | {} | |
| 86 | }; | ||
| 87 | |||
| 88 | /// Exception for signalling invalid arguments. | ||
| 89 | class invalid_argument_exception : public imgdoc2_exception | ||
| 90 | { | ||
| 91 | public: | ||
| 92 | /// Constructor. | ||
| 93 | /// \param error_message Message describing the error. | ||
| 94 | 6 | explicit invalid_argument_exception(const char* error_message) | |
| 95 | 6 | : imgdoc2_exception(error_message) | |
| 96 | 6 | {} | |
| 97 | }; | ||
| 98 | |||
| 99 | /// Exception for signalling that an attempt was made to access an non existing tile. | ||
| 100 | class non_existing_tile_exception : public imgdoc2_exception | ||
| 101 | { | ||
| 102 | private: | ||
| 103 | bool index_valid_{ false }; | ||
| 104 | imgdoc2::dbIndex index_{ 0 }; | ||
| 105 | public: | ||
| 106 | non_existing_tile_exception() = delete; | ||
| 107 | |||
| 108 | /// Constructor which specifies the primary key of the non existing tile. | ||
| 109 | /// \param error_message Message describing the error. | ||
| 110 | /// \param index The primary key of the non existing tile. | ||
| 111 | 10 | explicit non_existing_tile_exception(const std::string& error_message, imgdoc2::dbIndex index) | |
| 112 | 10 | : non_existing_tile_exception(error_message.c_str(), index) | |
| 113 | 10 | {} | |
| 114 | |||
| 115 | /// Constructor which specifies the primary key of the non existing tile. | ||
| 116 | /// \param error_message Message describing the error. | ||
| 117 | /// \param index The primary key of the non existing tile. | ||
| 118 | 10 | explicit non_existing_tile_exception(const char* error_message, imgdoc2::dbIndex index) | |
| 119 | 10 | : imgdoc2_exception(error_message), | |
| 120 | 10 | index_valid_(true), | |
| 121 | 10 | index_(index) | |
| 122 | 10 | {} | |
| 123 | |||
| 124 | /// Gets a boolean indicating whether the primary key of the faulty tile access is valid. | ||
| 125 | /// \returns True if the primary key is valid; false otherwise. | ||
| 126 | [[nodiscard]] bool IsIndexValid() const { return this->index_valid_; } | ||
| 127 | |||
| 128 | /// Gets the primary key of the non existing tile which was attempted to be accessed. Check non_existing_tile_exception::IsIndexValid() whether | ||
| 129 | /// this property is valid. | ||
| 130 | /// \returns The index of the non existing tile which was attempted to be accessed. | ||
| 131 | [[nodiscard]] imgdoc2::dbIndex GetIndex() const { return this->index_; } | ||
| 132 | }; | ||
| 133 | |||
| 134 | /// Exception for signalling that an invalid path was specified. | ||
| 135 | class invalid_path_exception : public imgdoc2_exception | ||
| 136 | { | ||
| 137 | public: | ||
| 138 | invalid_path_exception() = delete; | ||
| 139 | |||
| 140 | /// Constructor which specifies the primary key of the non existing tile. | ||
| 141 | /// \param error_message Message describing the error. | ||
| 142 | 34 | explicit invalid_path_exception(const std::string& error_message) | |
| 143 | 34 | : imgdoc2_exception(error_message.c_str()) | |
| 144 | 34 | {} | |
| 145 | |||
| 146 | /// Constructor which specifies the primary key of the non existing tile. | ||
| 147 | /// \param error_message Message describing the error. | ||
| 148 | 12 | explicit invalid_path_exception(const char* error_message) | |
| 149 | 12 | : imgdoc2_exception(error_message) | |
| 150 | 12 | {} | |
| 151 | }; | ||
| 152 | |||
| 153 | /// Exception for signalling that an attempt was made to access an non existing metadata item. | ||
| 154 | class non_existing_item_exception : public imgdoc2_exception | ||
| 155 | { | ||
| 156 | private: | ||
| 157 | bool index_valid_{ false }; | ||
| 158 | imgdoc2::dbIndex index_{ 0 }; | ||
| 159 | public: | ||
| 160 | non_existing_item_exception() = delete; | ||
| 161 | |||
| 162 | /// Constructor which specifies the primary key of the non existing tile. | ||
| 163 | /// \param error_message Message describing the error. | ||
| 164 | /// \param index The primary key of the non existing tile. | ||
| 165 | 64 | explicit non_existing_item_exception(const std::string& error_message, imgdoc2::dbIndex index) | |
| 166 | 64 | : non_existing_item_exception(error_message.c_str(), index) | |
| 167 | 64 | {} | |
| 168 | |||
| 169 | /// Constructor which specifies the primary key of the non existing tile. | ||
| 170 | /// \param error_message Message describing the error. | ||
| 171 | /// \param index The primary key of the non existing tile. | ||
| 172 | 64 | explicit non_existing_item_exception(const char* error_message, imgdoc2::dbIndex index) | |
| 173 | 64 | : imgdoc2_exception(error_message), | |
| 174 | 64 | index_valid_(true), | |
| 175 | 64 | index_(index) | |
| 176 | 64 | {} | |
| 177 | |||
| 178 | /// Gets a boolean indicating whether the primary key of the faulty item access is valid. | ||
| 179 | /// \returns True if the primary key is valid; false otherwise. | ||
| 180 | [[nodiscard]] bool IsIndexValid() const { return this->index_valid_; } | ||
| 181 | |||
| 182 | /// Gets the primary key of the non existing item which was attempted to be accessed. Check non_existing_item_exception::IsIndexValid() whether | ||
| 183 | /// this property is valid. | ||
| 184 | /// \returns The index of the non existing item which was attempted to be accessed. | ||
| 185 | [[nodiscard]] imgdoc2::dbIndex GetIndex() const { return this->index_; } | ||
| 186 | }; | ||
| 187 | |||
| 188 | /// Exception for signalling an unexpected internal error condition. | ||
| 189 | class internal_error_exception : public imgdoc2_exception | ||
| 190 | { | ||
| 191 | public: | ||
| 192 | internal_error_exception() = delete; | ||
| 193 | |||
| 194 | /// Constructor. | ||
| 195 | /// \param error_message Message describing the error. | ||
| 196 | ✗ | explicit internal_error_exception(const std::string& error_message) | |
| 197 | ✗ | : imgdoc2_exception(error_message.c_str()) | |
| 198 | ✗ | {} | |
| 199 | }; | ||
| 200 | } | ||
| 201 |