IDS peak IPL  v1.9.2
peak_ipl_exception.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
14 
15 #include <cstddef>
16 #include <cstdlib>
17 #include <cstring>
18 #include <sstream>
19 #include <stdexcept>
20 #include <string>
21 #include <vector>
22 
26 namespace peak
27 {
28 namespace ipl
29 {
30 
34 class Exception : public std::runtime_error
35 {
36  using std::runtime_error::runtime_error;
37 };
38 
43 {
44  using Exception::Exception;
45 };
46 
51 {
52  using Exception::Exception;
53 };
54 
59 {
60  using Exception::Exception;
61 };
62 
67 {
68  using Exception::Exception;
69 };
70 
75 {
76  using Exception::Exception;
77 };
78 
82 class IOException : public Exception
83 {
84  using Exception::Exception;
85 };
86 
90 class BusyException : public Exception
91 {
92  using Exception::Exception;
93 };
94 
99 {
100  using Exception::Exception;
101 };
102 
107 {
108  using Exception::Exception;
109 };
110 
115 {
116  using Exception::Exception;
117 };
118 
120 {
121  std::string entryString;
122 
123  switch(entry)
124  {
126  entryString = "PEAK_IPL_RETURN_CODE_SUCCESS";
127  break;
128 
130  entryString = "PEAK_IPL_RETURN_CODE_ERROR";
131  break;
132 
134  entryString = "PEAK_IPL_RETURN_CODE_BUFFER_TOO_SMALL";
135  break;
136 
138  entryString = "PEAK_IPL_RETURN_CODE_INVALID_ARGUMENT";
139  break;
140 
142  entryString = "PEAK_IPL_RETURN_CODE_INVALID_HANDLE";
143  break;
144 
146  entryString = "PEAK_IPL_RETURN_CODE_OUT_OF_RANGE";
147  break;
148 
150  entryString = "PEAK_IPL_RETURN_CODE_IMAGE_FORMAT_NOT_SUPPORTED";
151  break;
152 
154  entryString = "PEAK_IPL_RETURN_CODE_IO_ERROR";
155  break;
156 
158  entryString = "limgTypeRETURN_CODE_BUSY";
159  break;
160 
162  entryString = "limgTypeRETURN_CODE_TIMEOUT";
163  break;
164 
166  entryString = "PEAK_IPL_RETURN_CODE_FORMAT_INTERPRETATION_ERROR";
167  break;
168 
170  entryString = "limgTypeRETURN_CODE_NOT_SUPPORTED";
171  break;
172 
174  entryString = "limgTypeRETURN_CODE_NOT_PERMITTED";
175  break;
176  }
177 
178  return entryString;
179 }
180 
181 template <class CallableType>
182 void ExecuteAndMapReturnCodes(const CallableType& callableObject)
183 {
184  if (callableObject() != PEAK_IPL_RETURN_CODE_SUCCESS)
185  {
187  size_t lastErrorDescriptionSize = 0;
188  if (PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Library_GetLastError(&lastErrorCode, nullptr, &lastErrorDescriptionSize)
190  {
191  throw Exception("Could not query the last error!");
192  }
193  std::vector<char> lastErrorDescription(lastErrorDescriptionSize);
195  &lastErrorCode, lastErrorDescription.data(), &lastErrorDescriptionSize)
197  {
198  throw Exception("Could not query the last error!");
199  }
200 
201  std::stringstream errorText;
202  errorText << "[Error-Code: " << lastErrorCode << " ("
203  << StringFromPEAK_IPL_RETURN_CODE(static_cast<PEAK_IPL_RETURN_CODE_t>(lastErrorCode))
204  << ") | Error-Description: " << lastErrorDescription.data() << "]";
205 
206  switch (lastErrorCode)
207  {
209  throw OutOfRangeException(errorText.str().c_str());
211  throw InvalidArgumentException(errorText.str().c_str());
213  throw ImageFormatNotSupportedException(errorText.str().c_str());
215  throw ImageFormatInterpretationException(errorText.str().c_str());
217  throw IOException(errorText.str().c_str());
219  throw BufferTooSmallException(errorText.str().c_str());
221  throw NotPermittedException(errorText.str().c_str());
223  throw BusyException(errorText.str().c_str());
225  throw InvalidHandleException(errorText.str().c_str());
227  throw TimeoutException(errorText.str().c_str());
228  default:
229  throw Exception(errorText.str().c_str());
230  }
231  }
232 }
233 
234 } /* namespace ipl */
235 } /* namespace peak */
The exception thrown when the operation not permitted.
Definition: peak_ipl_exception.hpp:98
Definition: peak_ipl_backend.h:49
PEAK_IPL_C_API PEAK_IPL_Library_GetLastError(PEAK_IPL_RETURN_CODE *lastErrorCode, char *lastErrorDescription, size_t *lastErrorDescriptionSize)
Queries the last error.
#define PEAK_IPL_C_ABI_PREFIX
Definition: peak_ipl_dll_defines.h:16
The exception thrown when the operation times out.
Definition: peak_ipl_exception.hpp:106
The base class for all exceptions thrown by the library.
Definition: peak_ipl_exception.hpp:34
Definition: peak_ipl_backend.h:53
int32_t PEAK_IPL_RETURN_CODE
Definition: peak_ipl_backend.h:61
The "peak::ipl" namespace contains the whole image processing library.
Definition: peak_ipl_binning.hpp:22
Definition: peak_ipl_backend.h:51
The exception thrown when a given image format can&#39;t be used on this data, e.g. during reading from f...
Definition: peak_ipl_exception.hpp:82
Definition: peak_ipl_backend.h:57
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition: peak_ipl_exception.hpp:182
Definition: peak_ipl_backend.h:52
Definition: peak_ipl_backend.h:58
The exception thrown when passing an invalid parameter to a function.
Definition: peak_ipl_exception.hpp:58
Definition: peak_ipl_backend.h:50
The exception thrown for trying to access a value being out of range.
Definition: peak_ipl_exception.hpp:42
The exception thrown when a given buffer is too small for the data.
Definition: peak_ipl_exception.hpp:50
Definition: peak_ipl_backend.h:46
std::string StringFromPEAK_IPL_RETURN_CODE(PEAK_IPL_RETURN_CODE_t entry)
Definition: peak_ipl_exception.hpp:119
Definition: peak_ipl_backend.h:56
Definition: peak_ipl_backend.h:48
Definition: peak_ipl_backend.h:54
Definition: peak_ipl_backend.h:47
The exception thrown when a given image format can&#39;t be used on this data, e.g. during reading from f...
Definition: peak_ipl_exception.hpp:74
PEAK_IPL_RETURN_CODE_t
Definition: peak_ipl_backend.h:44
The exception thrown when the resource busy.
Definition: peak_ipl_exception.hpp:90
The exception thrown when passing an invalid handle to a function.
Definition: peak_ipl_exception.hpp:114
Definition: peak_ipl_backend.h:55
The exception thrown when an image format isn&#39;t supported by a function.
Definition: peak_ipl_exception.hpp:66