IDS peak ICV v1.2.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 */
Thrown when input data or a file is malformed, unreadable, or otherwise corrupted.
The base class for all exceptions thrown by the IDS peak ICV library.
Thrown when a file input/output operation fails.
Thrown on unexpected internal system errors.
Thrown when the library configuration is invalid.
Thrown when a mathematical computation fails.
Thrown when input parameters do not match the expected conditions.
Thrown when an operation cannot be performed due to logical constraints.
Thrown when a requested operation is not implemented or supported.
Thrown when attempting to access an object or value that has not been initialized.
Thrown when a value is outside the allowed range.
Thrown when an expected target object is not detected in the input image.
void ExecuteAndMapReturnCodesLight(const CallableType &callableObject)
void ExecuteAndMapReturnCodes(const CallableType &callableObject)