IDS peak IPL v1.13.1
Loading...
Searching...
No Matches
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
26namespace peak
27{
28namespace ipl
29{
30
34class 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
82class IOException : public Exception
83{
84 using Exception::Exception;
85};
86
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 = "PEAK_IPL_RETURN_CODE_BUSY";
159 break;
160
162 entryString = "PEAK_IPL_RETURN_CODE_TIMEOUT";
163 break;
164
166 entryString = "PEAK_IPL_RETURN_CODE_FORMAT_INTERPRETATION_ERROR";
167 break;
168
170 entryString = "PEAK_IPL_RETURN_CODE_NOT_SUPPORTED";
171 break;
172
174 entryString = "PEAK_IPL_RETURN_CODE_NOT_PERMITTED";
175 break;
176 }
177
178 return entryString;
179}
180
181template <class CallableType>
182void 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 a given buffer is too small for the data.
Definition peak_ipl_exception.hpp:51
The exception thrown when the resource busy.
Definition peak_ipl_exception.hpp:91
The base class for all exceptions thrown by the library.
Definition peak_ipl_exception.hpp:35
The exception thrown when a given image format can't be used on this data, e.g. during reading from f...
Definition peak_ipl_exception.hpp:83
The exception thrown when a given image format can't be used on this data, e.g. during reading from f...
Definition peak_ipl_exception.hpp:75
The exception thrown when an image format isn't supported by a function.
Definition peak_ipl_exception.hpp:67
The exception thrown when passing an invalid parameter to a function.
Definition peak_ipl_exception.hpp:59
The exception thrown when passing an invalid handle to a function.
Definition peak_ipl_exception.hpp:115
The exception thrown when the operation not permitted.
Definition peak_ipl_exception.hpp:99
The exception thrown for trying to access a value being out of range.
Definition peak_ipl_exception.hpp:43
The exception thrown when the operation times out.
Definition peak_ipl_exception.hpp:107
std::string StringFromPEAK_IPL_RETURN_CODE(PEAK_IPL_RETURN_CODE_t entry)
Definition peak_ipl_exception.hpp:119
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition peak_ipl_exception.hpp:182
The "peak::ipl" namespace contains the whole image processing library.
Definition peak_ipl_binning.hpp:23
int32_t PEAK_IPL_RETURN_CODE
Definition peak_ipl_backend.h:61
PEAK_IPL_C_API PEAK_IPL_Library_GetLastError(PEAK_IPL_RETURN_CODE *lastErrorCode, char *lastErrorDescription, size_t *lastErrorDescriptionSize)
Queries the last error.
PEAK_IPL_RETURN_CODE_t
Definition peak_ipl_backend.h:45
@ PEAK_IPL_RETURN_CODE_SUCCESS
Definition peak_ipl_backend.h:46
@ PEAK_IPL_RETURN_CODE_OUT_OF_RANGE
Definition peak_ipl_backend.h:52
@ PEAK_IPL_RETURN_CODE_IO_ERROR
Definition peak_ipl_backend.h:49
@ PEAK_IPL_RETURN_CODE_FORMAT_INTERPRETATION_ERROR
Definition peak_ipl_backend.h:54
@ PEAK_IPL_RETURN_CODE_INVALID_HANDLE
Definition peak_ipl_backend.h:48
@ PEAK_IPL_RETURN_CODE_INVALID_ARGUMENT
Definition peak_ipl_backend.h:51
@ PEAK_IPL_RETURN_CODE_BUFFER_TOO_SMALL
Definition peak_ipl_backend.h:50
@ PEAK_IPL_RETURN_CODE_ERROR
Definition peak_ipl_backend.h:47
@ PEAK_IPL_RETURN_CODE_NOT_PERMITTED
Definition peak_ipl_backend.h:56
@ PEAK_IPL_RETURN_CODE_BUSY
Definition peak_ipl_backend.h:57
@ PEAK_IPL_RETURN_CODE_IMAGE_FORMAT_NOT_SUPPORTED
Definition peak_ipl_backend.h:53
@ PEAK_IPL_RETURN_CODE_TIMEOUT
Definition peak_ipl_backend.h:58
@ PEAK_IPL_RETURN_CODE_NOT_SUPPORTED
Definition peak_ipl_backend.h:55
#define PEAK_IPL_C_ABI_PREFIX
Definition peak_ipl_dll_defines.h:16