IDS peak IPL  v1.4.0
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 
88 {
89  std::string entryString;
90 
91  if (entry == PEAK_IPL_RETURN_CODE_SUCCESS)
92  {
93  entryString = "PEAK_IPL_RETURN_CODE_SUCCESS";
94  }
95  else if (entry == PEAK_IPL_RETURN_CODE_ERROR)
96  {
97  entryString = "PEAK_IPL_RETURN_CODE_ERROR";
98  }
99  else if (entry == PEAK_IPL_RETURN_CODE_BUFFER_TOO_SMALL)
100  {
101  entryString = "PEAK_IPL_RETURN_CODE_BUFFER_TOO_SMALL";
102  }
103  else if (entry == PEAK_IPL_RETURN_CODE_INVALID_ARGUMENT)
104  {
105  entryString = "PEAK_IPL_RETURN_CODE_INVALID_ARGUMENT";
106  }
107  else if (entry == PEAK_IPL_RETURN_CODE_INVALID_HANDLE)
108  {
109  entryString = "PEAK_IPL_RETURN_CODE_INVALID_HANDLE";
110  }
111  else if (entry == PEAK_IPL_RETURN_CODE_OUT_OF_RANGE)
112  {
113  entryString = "PEAK_IPL_RETURN_CODE_OUT_OF_RANGE";
114  }
116  {
117  entryString = "PEAK_IPL_RETURN_CODE_IMAGE_FORMAT_NOT_SUPPORTED";
118  }
119  else if (entry == PEAK_IPL_RETURN_CODE_IO_ERROR)
120  {
121  entryString = "PEAK_IPL_RETURN_CODE_IO_ERROR";
122  }
123 
124  return entryString;
125 }
126 
127 template <class CallableType>
128 void ExecuteAndMapReturnCodes(const CallableType& callableObject)
129 {
130  if (callableObject() != PEAK_IPL_RETURN_CODE_SUCCESS)
131  {
133  size_t lastErrorDescriptionSize = 0;
134  if (PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Library_GetLastError(&lastErrorCode, nullptr, &lastErrorDescriptionSize)
136  {
137  throw Exception("Could not query the last error!");
138  }
139  std::vector<char> lastErrorDescription(lastErrorDescriptionSize);
141  &lastErrorCode, lastErrorDescription.data(), &lastErrorDescriptionSize)
143  {
144  throw Exception("Could not query the last error!");
145  }
146 
147  std::stringstream errorText;
148  errorText << "[Error-Code: " << lastErrorCode << " ("
149  << StringFromPEAK_IPL_RETURN_CODE(static_cast<PEAK_IPL_RETURN_CODE_t>(lastErrorCode))
150  << ") | Error-Description: " << lastErrorDescription.data() << "]";
151 
152  switch (lastErrorCode)
153  {
155  throw OutOfRangeException(errorText.str().c_str());
157  throw InvalidArgumentException(errorText.str().c_str());
159  throw ImageFormatNotSupportedException(errorText.str().c_str());
161  throw ImageFormatInterpretationException(errorText.str().c_str());
163  throw IOException(errorText.str().c_str());
165  throw BufferTooSmallException(errorText.str().c_str());
166  default:
167  throw Exception(errorText.str().c_str());
168  }
169  }
170 }
171 
172 } /* namespace ipl */
173 } /* namespace peak */
Definition: peak_ipl_backend.h:33
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 base class for all exceptions thrown by the library.
Definition: peak_ipl_exception.hpp:34
Definition: peak_ipl_backend.h:37
int32_t PEAK_IPL_RETURN_CODE
Definition: peak_ipl_backend.h:41
The "peak::ipl" namespace contains the whole image processing library.
Definition: peak_ipl_binning.hpp:16
Definition: peak_ipl_backend.h:35
The exception thrown when an given image format can not be used on this data e.g. during reading from...
Definition: peak_ipl_exception.hpp:82
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition: peak_ipl_exception.hpp:128
Definition: peak_ipl_backend.h:36
The exception thrown when passing an invalid parameter to a function.
Definition: peak_ipl_exception.hpp:58
Definition: peak_ipl_backend.h:34
The exception thrown for trying to access a value being out of range.
Definition: peak_ipl_exception.hpp:42
The exception thrown when an given buffer is to small for for the data.
Definition: peak_ipl_exception.hpp:50
Definition: peak_ipl_backend.h:30
std::string StringFromPEAK_IPL_RETURN_CODE(PEAK_IPL_RETURN_CODE_t entry)
Definition: peak_ipl_exception.hpp:87
Definition: peak_ipl_backend.h:32
Definition: peak_ipl_backend.h:38
Definition: peak_ipl_backend.h:31
The exception thrown when an given image format can not be used on this data e.g. during reading from...
Definition: peak_ipl_exception.hpp:74
PEAK_IPL_RETURN_CODE_t
Definition: peak_ipl_backend.h:28
The exception thrown when an image format is not supported by a function.
Definition: peak_ipl_exception.hpp:66