libCZI
Reading and Writing CZI documents made easy
libCZI_exceptions.h
1 // SPDX-FileCopyrightText: 2017-2022 Carl Zeiss Microscopy GmbH
2 //
3 // SPDX-License-Identifier: LGPL-3.0-or-later
4 
5 #pragma once
6 
7 #include <exception>
8 #include <stdexcept>
9 #include <cstdint>
10 
11 namespace libCZI
12 {
14  class LibCZIException : public std::runtime_error
15  {
16  public:
19  explicit LibCZIException(const char* szErrMsg)
20  : std::runtime_error(szErrMsg)
21  {}
22  };
23 
26  {
27  public:
29  enum class ErrorType
30  {
33  };
34  private:
35  ErrorType errorType;
36  public:
41  LibCZIAccessorException(const char* szErrMsg, ErrorType errorType)
42  : LibCZIException(szErrMsg), errorType(errorType)
43  {}
44 
47  ErrorType GetErrorType() const { return this->errorType; }
48  };
49 
52  {
53  public:
55  enum class ErrorType
56  {
61  };
62  private:
63  ErrorType errorType;
64  int numberOfCharsParsedOk;
65  public:
66 
72  LibCZIStringParseException(const char* szErrMsg, int numberOfCharsParsedOk, ErrorType errorType)
73  : LibCZIException(szErrMsg), errorType(errorType), numberOfCharsParsedOk(numberOfCharsParsedOk)
74  {}
75 
78  ErrorType GetErrorType() const { return this->errorType; }
79 
83  int GetNumberOfCharsParsedOk() const { return this->numberOfCharsParsedOk; }
84  };
85 
86 
108  class LibCZIIOException : public LibCZIException, public std::nested_exception
109  {
110  private:
111  std::uint64_t offset;
112  std::uint64_t size;
113  public:
120  LibCZIIOException(const char* szErrMsg, std::uint64_t offset, std::uint64_t size)
121  : LibCZIException(szErrMsg), offset(offset), size(size) {}
122 
127  std::uint64_t GetOffset() const { return this->offset; }
128 
133  std::uint64_t GetSize() const { return this->size; }
134  };
135 
136 
139  {
141  enum class ErrorCode
142  {
143  NotEnoughData,
144  CorruptedData,
147  };
148 
153  LibCZICZIParseException(const char* szErrMsg, ErrorCode code)
154  : LibCZIException(szErrMsg), errorCode(code)
155  {
156  }
157 
160  ErrorCode GetErrorCode() const { return this->errorCode; }
161  private:
162  ErrorCode errorCode;
163  };
164 
168  {
173  explicit LibCZISegmentNotPresent(const char* szErrMsg)
174  : LibCZIException(szErrMsg)
175  {
176  }
177  };
178 
181  {
183  enum class ErrorCode
184  {
189  };
190 
196  : LibCZIException(szErrMsg), errorCode(code)
197  {
198  }
199  private:
200  ErrorCode errorCode;
201  };
202 
205  {
206  public:
208  enum class ErrorType
209  {
217  };
218 
223  LibCZIWriteException(const char* szErrMsg, ErrorType code)
224  : LibCZIException(szErrMsg), errorType(code)
225  {
226  }
227 
230  ErrorType GetErrorType() const { return this->errorType; }
231 
232  private:
233  ErrorType errorType;
234  };
235 
238  {
239  public:
241  enum class ErrorType
242  {
247  };
248 
253  LibCZIReaderWriteException(const char* szErrMsg, ErrorType code)
254  : LibCZIException(szErrMsg), errorType(code)
255  {
256  }
257 
260  ErrorType GetErrorType() const { return this->errorType; }
261 
262  private:
263  ErrorType errorType;
264  };
265 
268  {
269  public:
271  enum class ErrorType
272  {
273  InvalidPath,
275  };
276 
281  LibCZIMetadataBuilderException(const char* szErrMsg, ErrorType code)
282  : LibCZIException(szErrMsg), errorType(code)
283  {
284  }
285 
288  ErrorType GetErrorType() const { return this->errorType; }
289 
290  private:
291  ErrorType errorType;
292  };
293 
296  {
297  public:
299  enum class ErrorType
300  {
301  InvalidPath,
302  };
303 
308  LibCZIMetadataException(const char* szErrMsg, ErrorType code)
309  : LibCZIException(szErrMsg), errorType(code)
310  {
311  }
312 
315  ErrorType GetErrorType() const { return this->errorType; }
316 
317  private:
318  ErrorType errorType;
319  };
320 
323  {
324  public:
328  explicit LibCZIXmlParseException(const char* szErrMsg)
329  : LibCZIException(szErrMsg)
330  {
331  }
332  };
333 }
334 
Exception for signaling errors specific for accessors.
Definition: libCZI_exceptions.h:26
LibCZIAccessorException(const char *szErrMsg, ErrorType errorType)
Definition: libCZI_exceptions.h:41
ErrorType GetErrorType() const
Definition: libCZI_exceptions.h:47
ErrorType
Values that represent error types.
Definition: libCZI_exceptions.h:30
@ CouldntDeterminePixelType
The pixeltype could not be determined.
Base class for all libCZI-specific exceptions.
Definition: libCZI_exceptions.h:15
LibCZIException(const char *szErrMsg)
Definition: libCZI_exceptions.h:19
Definition: libCZI_exceptions.h:109
std::uint64_t GetOffset() const
Definition: libCZI_exceptions.h:127
LibCZIIOException(const char *szErrMsg, std::uint64_t offset, std::uint64_t size)
Definition: libCZI_exceptions.h:120
std::uint64_t GetSize() const
Definition: libCZI_exceptions.h:133
Exception for signaling errors when using the Czi-metadata-builder-object.
Definition: libCZI_exceptions.h:268
ErrorType GetErrorType() const
Definition: libCZI_exceptions.h:288
LibCZIMetadataBuilderException(const char *szErrMsg, ErrorType code)
Definition: libCZI_exceptions.h:281
ErrorType
Values that represent different error conditions.
Definition: libCZI_exceptions.h:272
@ InvalidPath
the path specified in a call to ICziMetadataBuilder::GetOrCreateChildNode was invalid
@ CannotSetValueToNode
the node has subnodes, so cannot set a value
Exception for signaling errors when accessing the XML-metadata (.
Definition: libCZI_exceptions.h:296
ErrorType GetErrorType() const
Definition: libCZI_exceptions.h:315
ErrorType
Values that represent different error conditions.
Definition: libCZI_exceptions.h:300
@ InvalidPath
the path specified in a call to IXmlNodeRead::GetChildNodeReadonly was invalid
LibCZIMetadataException(const char *szErrMsg, ErrorType code)
Definition: libCZI_exceptions.h:308
Exception for signaling errors when using the CziReaderWriter-object.
Definition: libCZI_exceptions.h:238
LibCZIReaderWriteException(const char *szErrMsg, ErrorType code)
Definition: libCZI_exceptions.h:253
ErrorType
Values that represent different error conditions.
Definition: libCZI_exceptions.h:242
@ InvalidAttachmentId
An invalid attachment-id was specified.
@ AddCoordinateAlreadyExisting
A subblock with the same coordinate and same M-index was added before.
@ InvalidSubBlkId
An invalid subblock-id was specified.
@ AddAttachmentAlreadyExisting
An attachment with the same key was added before.
ErrorType GetErrorType() const
Definition: libCZI_exceptions.h:260
Exception for signaling that a string did not parse correctly.
Definition: libCZI_exceptions.h:52
ErrorType
Values that represent error types.
Definition: libCZI_exceptions.h:56
@ DuplicateDimension
When parsing a string representation of a coordinate, it was detected, that a dimension occurred more...
@ InvalidSyntax
The string parsed has an invalid syntax.
@ FromGreaterThanTo
A range was parsed, and the start value is bigger than the end value.
LibCZIStringParseException(const char *szErrMsg, int numberOfCharsParsedOk, ErrorType errorType)
Definition: libCZI_exceptions.h:72
int GetNumberOfCharsParsedOk() const
Definition: libCZI_exceptions.h:83
ErrorType GetErrorType() const
Definition: libCZI_exceptions.h:78
Exception for signaling errors when using the CziWriter-object.
Definition: libCZI_exceptions.h:205
ErrorType GetErrorType() const
Definition: libCZI_exceptions.h:230
LibCZIWriteException(const char *szErrMsg, ErrorType code)
Definition: libCZI_exceptions.h:223
ErrorType
Values that represent different error conditions.
Definition: libCZI_exceptions.h:209
@ AddCoordinateContainsUnexpectedDimension
the coordinate of the subblock to be added contains a dimension that was not expected.
@ SubBlockCoordinateOutOfBounds
The subblock's coordinate was determined to be out-of-bounds.
@ AddCoordinateAlreadyExisting
A subblock with the same coordinate and same M-index was added before.
@ SubBlockCoordinateInsufficient
The subblock's coordinate was determined to be insufficient.
@ AddAttachmentAlreadyExisting
An attachment with the same key was added before.
@ GetDataCallError
A call to a getData-functor gave an invalid result.
@ NotEnoughDataWritten
A write-operation reported that less data was written than requested.
Exception for signaling errors when parsing the XML-metadata.
Definition: libCZI_exceptions.h:323
LibCZIXmlParseException(const char *szErrMsg)
Definition: libCZI_exceptions.h:328
External interfaces, classes, functions and structs are found in the namespace "libCZI".
Definition: libCZI.h:31
Exception for signaling errors parsing the CZI-stream.
Definition: libCZI_exceptions.h:139
ErrorCode
Values that represent different error conditions.
Definition: libCZI_exceptions.h:142
@ CorruptedData
An enum constant representing that the data was detected to be bogus.
@ InternalError
An internal error was detected.
@ NonConformingSubBlockDimensionEntry
An enum constant representing that the dimension-entry of a subblock was found to be non-conforming.
@ NotEnoughData
An enum constant representing that not the expected amount of data could be read.
LibCZICZIParseException(const char *szErrMsg, ErrorCode code)
Definition: libCZI_exceptions.h:153
ErrorCode GetErrorCode() const
Definition: libCZI_exceptions.h:160
Exception for signaling an incorrect plane-coordinate object.
Definition: libCZI_exceptions.h:181
ErrorCode
Values that represent different error conditions.
Definition: libCZI_exceptions.h:184
@ MissingDimension
An enum constant representing that the plane-coordinate did not contain a coordinate which is require...
@ SurplusDimension
An enum constant representing a dimension was specified which is not found in the document.
@ InvalidDimension
An enum constant representing that the plane-coordinate contained a dimension which is not used to sp...
@ CoordinateOutOfRange
An enum constant representing that a coordinate was given which is out-of-range.
LibCZIInvalidPlaneCoordinateException(const char *szErrMsg, ErrorCode code)
Definition: libCZI_exceptions.h:195
Definition: libCZI_exceptions.h:168
LibCZISegmentNotPresent(const char *szErrMsg)
Definition: libCZI_exceptions.h:173