libCZI
Reading CZI documents made easy
libCZI_exceptions.h
1 //******************************************************************************
2 //
3 // libCZI is a reader for the CZI fileformat written in C++
4 // Copyright (C) 2017 Zeiss Microscopy GmbH
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 //
19 // To obtain a commercial version please contact Zeiss Microscopy GmbH.
20 //
21 //******************************************************************************
22 
23 #pragma once
24 
25 #include <exception>
26 #include <stdexcept>
27 
28 namespace libCZI
29 {
31  class LibCZIException : public std::runtime_error
32  {
33  public:
36  explicit LibCZIException(const char* szErrMsg)
37  : std::runtime_error(szErrMsg)
38  {}
39  };
40 
43  {
44  public:
46  enum class ErrorType
47  {
48  CouldntDeterminePixelType,
50  };
51  private:
52  ErrorType errorType;
53  public:
58  LibCZIAccessorException(const char* szErrMsg, ErrorType errorType)
59  : LibCZIException(szErrMsg), errorType(errorType)
60  {}
61 
64  ErrorType GetErrorType() const { return this->errorType; };
65  };
66 
69  {
70  public:
72  enum class ErrorType
73  {
74  InvalidSyntax,
75  DuplicateDimension,
76  FromGreaterThanTo,
78  };
79  private:
80  ErrorType errorType;
81  int numberOfCharsParsedOk;
82  public:
83 
89  LibCZIStringParseException(const char* szErrMsg, int numberOfCharsParsedOk, ErrorType errorType)
90  : LibCZIException(szErrMsg), errorType(errorType), numberOfCharsParsedOk(numberOfCharsParsedOk)
91  {}
92 
95  ErrorType GetErrorType() const { return this->errorType; };
96 
100  int GetNumberOfCharsParsedOk() const { return this->numberOfCharsParsedOk; }
101  };
102 
103 
125  class LibCZIIOException : public LibCZIException, public std::nested_exception
126  {
127  private:
128  std::uint64_t offset;
129  std::uint64_t size;
130  public:
137  LibCZIIOException(const char* szErrMsg, std::uint64_t offset, std::uint64_t size)
138  : LibCZIException(szErrMsg), offset(offset), size(size) {}
139 
144  std::uint64_t GetOffset() const { return this->offset; }
145 
150  std::uint64_t GetSize() const { return this->size; }
151  };
152 
153 
156  {
158  enum class ErrorCode
159  {
160  NotEnoughData,
161  CorruptedData,
162  InternalError
163  };
164 
169  LibCZICZIParseException(const char* szErrMsg, ErrorCode code)
170  : LibCZIException(szErrMsg), errorCode(code)
171  {
172  }
173 
176  ErrorCode GetErrorCode() const { return this->errorCode; }
177  private:
178  ErrorCode errorCode;
179  };
180 
183  {
185  enum class ErrorCode
186  {
187  SurplusDimension,
188  MissingDimension,
189  InvalidDimension,
190  CoordinateOutOfRange
191  };
192 
198  : LibCZIException(szErrMsg), errorCode(code)
199  {
200  }
201  private:
202  ErrorCode errorCode;
203  };
204 
207  {
208  public:
210  enum class ErrorType
211  {
212  InvalidPath,
213  };
214 
219  LibCZIMetadataException(const char* szErrMsg, ErrorType code)
220  : LibCZIException(szErrMsg), errorType(code)
221  {
222  }
223 
226  ErrorType GetErrorType() const { return this->errorType; }
227 
228  private:
229  ErrorType errorType;
230  };
231 
234  {
235  public:
239  LibCZIXmlParseException(const char* szErrMsg)
240  : LibCZIException(szErrMsg)
241  {
242  }
243  };
244 
247  {
248  public:
250  enum class ErrorType
251  {
252  SyntaxError,
253  UnbalancedParenthesis,
254  IllformedExpression,
255  InvalidNumberFormat
256  };
257  private:
258  ErrorType errorType;
259  int parseErrorAfterCharNo;
260  public:
265  LibCZIQueryParseException(const char* szErrMsg, ErrorType errorType)
266  : LibCZIQueryParseException(szErrMsg, errorType, -1)
267  {}
268 
274  explicit LibCZIQueryParseException(const char* szErrMsg, ErrorType errorType, int indexOfParseError)
275  : LibCZIException(szErrMsg),
276  errorType(errorType),
277  parseErrorAfterCharNo(indexOfParseError)
278  {}
279 
282  ErrorType GetErrorType() const { return this->errorType; }
283 
287  int GetPositionAfterWhichParserErrorOccurred() const { return this->parseErrorAfterCharNo; }
288  };
289 
292  {
293  public:
295  enum class ErrorType
296  {
297  NonExistentDimension,
298  InternalError
299  };
300  private:
301  ErrorType errorType;
302  public:
307  explicit LibCZIQueryExecutionException(const char* szErrMsg, ErrorType errorType)
308  : LibCZIException(szErrMsg),
309  errorType(errorType)
310  {}
311 
316  explicit LibCZIQueryExecutionException(const std::string& errMsg, ErrorType errorType)
317  : LibCZIQueryExecutionException(errMsg.c_str(), errorType)
318  {}
319 
322  ErrorType GetErrorType() const { return this->errorType; }
323  };
324 }
325 
LibCZIQueryExecutionException(const char *szErrMsg, ErrorType errorType)
Definition: libCZI_exceptions.h:307
Exception for signaling that a string did not parse correctly.
Definition: libCZI_exceptions.h:68
ErrorCode
Values that represent different error conditions.
Definition: libCZI_exceptions.h:185
int GetNumberOfCharsParsedOk() const
Definition: libCZI_exceptions.h:100
ErrorType
Values that represent error types.
Definition: libCZI_exceptions.h:46
ErrorType GetErrorType() const
Definition: libCZI_exceptions.h:282
Base class for all libCZI-specific exceptions.
Definition: libCZI_exceptions.h:31
Exception for signaling errors when evaluating a query.
Definition: libCZI_exceptions.h:291
LibCZIException(const char *szErrMsg)
Definition: libCZI_exceptions.h:36
Exception for signaling errors specific for accessors.
Definition: libCZI_exceptions.h:42
Definition: libCZI_exceptions.h:125
ErrorCode
Values that represent different error conditions.
Definition: libCZI_exceptions.h:158
LibCZIQueryExecutionException(const std::string &errMsg, ErrorType errorType)
Definition: libCZI_exceptions.h:316
LibCZIQueryParseException(const char *szErrMsg, ErrorType errorType)
Definition: libCZI_exceptions.h:265
ErrorType
Values that represent different error conditions.
Definition: libCZI_exceptions.h:295
LibCZIAccessorException(const char *szErrMsg, ErrorType errorType)
Definition: libCZI_exceptions.h:58
std::uint64_t GetSize() const
Definition: libCZI_exceptions.h:150
LibCZIIOException(const char *szErrMsg, std::uint64_t offset, std::uint64_t size)
Definition: libCZI_exceptions.h:137
std::uint64_t GetOffset() const
Definition: libCZI_exceptions.h:144
Exception for signaling errors when parsing a query-string.
Definition: libCZI_exceptions.h:246
LibCZIQueryParseException(const char *szErrMsg, ErrorType errorType, int indexOfParseError)
Definition: libCZI_exceptions.h:274
Exception for signaling errors parsing the CZI-stream.
Definition: libCZI_exceptions.h:155
ErrorType
Values that represent error types.
Definition: libCZI_exceptions.h:72
LibCZIStringParseException(const char *szErrMsg, int numberOfCharsParsedOk, ErrorType errorType)
Definition: libCZI_exceptions.h:89
ErrorType GetErrorType() const
Definition: libCZI_exceptions.h:322
LibCZIXmlParseException(const char *szErrMsg)
Definition: libCZI_exceptions.h:239
Exception for signaling errors when parsing the XML-metadata.
Definition: libCZI_exceptions.h:233
ErrorCode GetErrorCode() const
Definition: libCZI_exceptions.h:176
LibCZIInvalidPlaneCoordinateException(const char *szErrMsg, ErrorCode code)
Definition: libCZI_exceptions.h:197
External interfaces, classes, functions and structs are found in the namespace "libCZI".
Definition: libCZI.h:45
ErrorType GetErrorType() const
Definition: libCZI_exceptions.h:95
LibCZIMetadataException(const char *szErrMsg, ErrorType code)
Definition: libCZI_exceptions.h:219
Exception for signaling an incorrect plane-coordinate object.
Definition: libCZI_exceptions.h:182
int GetPositionAfterWhichParserErrorOccurred() const
Definition: libCZI_exceptions.h:287
ErrorType GetErrorType() const
Definition: libCZI_exceptions.h:64
LibCZICZIParseException(const char *szErrMsg, ErrorCode code)
Definition: libCZI_exceptions.h:169
ErrorType
Values that represent different error conditions.
Definition: libCZI_exceptions.h:250
Exception for signaling errors when accessing the XML-metadata.
Definition: libCZI_exceptions.h:206
ErrorType GetErrorType() const
Definition: libCZI_exceptions.h:226
ErrorType
Values that represent different error conditions.
Definition: libCZI_exceptions.h:210