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  {
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  {
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  : offset(offset), size(size), LibCZIException(szErrMsg) {}
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,
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  {
191  };
192 
198  : LibCZIException(szErrMsg), errorCode(code)
199  {
200  }
201  private:
202  ErrorCode errorCode;
203  };
204 }
205 
Exception for signalling 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
Base class for all libCZI-specific exceptions.
Definition: libCZI_exceptions.h:31
LibCZIException(const char *szErrMsg)
Definition: libCZI_exceptions.h:36
Exception for signalling errors specific for accessors.
Definition: libCZI_exceptions.h:42
Definition: libCZI_exceptions.h:125
The string parsed has an invalid syntax.
ErrorCode
Values that represent different error conditions.
Definition: libCZI_exceptions.h:158
An enum constant representing that not the expected amount of data could be read. ...
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
An enum constant representing that the plane-coordinate contained a dimension which is not used to sp...
Exception for signalling 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
An enum constant representing that the plane-coordinate did not contain a coordinate which is require...
When parsing a string representation of a coordinate, it was detected, that a dimension occured more ...
ErrorCode GetErrorCode() const
Definition: libCZI_exceptions.h:176
LibCZIInvalidPlaneCoordinateException(const char *szErrMsg, ErrorCode code)
Definition: libCZI_exceptions.h:197
An enum constant representing that the data was detected to be bogus.
External interfaces, classes, functions and structs are found in the namespace "libCZI".
Definition: libCZI.h:44
ErrorType GetErrorType() const
Definition: libCZI_exceptions.h:95
A range was parsed, and the start value is bigger than the end value.
Exception for signalling an incorrect plane-coordinate object.
Definition: libCZI_exceptions.h:182
ErrorType GetErrorType() const
Definition: libCZI_exceptions.h:64
LibCZICZIParseException(const char *szErrMsg, ErrorCode code)
Definition: libCZI_exceptions.h:169
An enum constant representing a dimension was specified which is not found in the document...
An enum constant representing that a coordinate was given which is out-of-range.