IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
peak_icv_exception_helpers.hpp
Go to the documentation of this file.
1
11#pragma once
12
14#include <peak_icv_c/backend/peak_icv_dll_defines.h>
15#include <peak_icv_c/library/peak_icv_library.h>
16#include <peak_icv_c/types/peak_icv_simple_types.h>
17
18#include <stdexcept>
19#include <vector>
20
21namespace peak
22{
23namespace icv
24{
25namespace detail
26{
27namespace last_error
28{
29template <class CallableType>
30void ExecuteAndMapReturnCodesLight(const CallableType& callableObject)
31{
32 const auto errorCode = callableObject();
33 if (errorCode != PEAK_ICV_STATUS_SUCCESS)
34 {
35 throw Exception("Could not query the last error!", PEAK_ICV_STATUS_INTERNAL_ERROR);
36 }
37}
38
39inline std::string GetLastError()
40{
41 size_t lastErrorDescriptionSize{};
43 return PEAK_ICV_C_ABI_PREFIX peak_icv_GetLastErrorMessage_GetCount(&lastErrorDescriptionSize);
44 });
45
46 std::vector<char> lastErrorDescription(lastErrorDescriptionSize);
48 return PEAK_ICV_C_ABI_PREFIX peak_icv_GetLastErrorMessage(lastErrorDescription.data(), lastErrorDescriptionSize);
49 });
50
51 return { lastErrorDescription.data() };
52}
53} // namespace last_error
54
55template <class CallableType>
56void ExecuteAndMapReturnCodes(const CallableType& callableObject)
57{
58 const auto errorCode = callableObject();
59 if (errorCode != PEAK_ICV_STATUS_SUCCESS)
60 {
61 std::string errorText = last_error::GetLastError();
62
63 switch (errorCode)
64 {
65 case PEAK_ICV_STATUS_LIBRARY_NOT_INITIALIZED:
66 case PEAK_ICV_STATUS_DYNAMIC_DEPENDENCY_MISSING:
67 throw InvalidConfigurationException(errorText, errorCode);
68
69 case PEAK_ICV_STATUS_NULL_POINTER:
70 throw NullPointerException(errorText);
71
72 case PEAK_ICV_STATUS_MISMATCH:
73 throw MismatchException(errorText);
74
75 case PEAK_ICV_STATUS_NOT_SUPPORTED:
76 throw NotSupportedException(errorText);
77
78 case PEAK_ICV_STATUS_NOT_POSSIBLE:
79 throw NotPossibleException(errorText);
80
81 case PEAK_ICV_STATUS_OUT_OF_RANGE:
82 throw OutOfRangeException(errorText);
83
84 case PEAK_ICV_STATUS_MATH_ERROR:
85 throw MathErrorException(errorText);
86
87 case PEAK_ICV_STATUS_TARGET_NOT_FOUND:
88 throw TargetNotFoundException(errorText);
89
90 case PEAK_ICV_STATUS_CORRUPTED:
91 throw CorruptedException(errorText);
92
93 case PEAK_ICV_STATUS_IO_ERROR:
94 throw IOException(errorText);
95
96 case PEAK_ICV_STATUS_INTERNAL_ERROR:
97 case PEAK_ICV_STATUS_INVALID_BUFFER_SIZE:
98 case PEAK_ICV_STATUS_INVALID_HANDLE:
99 throw InternalErrorException(errorText, errorCode);
100
101 default:
102 throw Exception("Generic Error!", errorCode);
103 }
104 }
105}
106
107} // namespace detail
108
109} /* namespace icv */
110} /* namespace peak */
Occurs when reading from a file or stream that is incomplete, damaged, or in an unexpected format.
Base class for all exceptions thrown by the IDS peak ICV library.
Occurs when a file operation fails (e.g., missing file, insufficient permissions, or inaccessible dir...
Occurs when a failure happens during processing due to an unhandled internal routine condition.
Occurs when a required dependency is missing, the library is not initialized, or a misconfiguration a...
Occurs when a mathematical computation fails (e.g., division by zero or invalid matrix operations).
Occurs when input parameters do not match expected conditions (e.g., two input images have different ...
Occurs when an operation cannot be performed due to logical constraints (e.g., camera calibration wit...
Occurs when a requested operation is not implemented or supported (e.g., exporting to an unsupported ...
Occurs when attempting to access an object or value via an uninitialized or null pointer.
Occurs when a provided value falls outside the allowed valid range.
Occurs when an expected target object (e.g., calibration plate or marker) is not detected in the inpu...
void ExecuteAndMapReturnCodesLight(const CallableType &callableObject)
void ExecuteAndMapReturnCodes(const CallableType &callableObject)