CVB++ 15.0
exception.hpp
1#pragma once
2
3
4#include <exception>
5#include <new>
6#include <stdexcept>
7
8#include "_cexports/c_error.h"
9
10#include "global.hpp"
11
12namespace Cvb
13{
14
15CVB_BEGIN_INLINE_NS
16
18namespace ErrorCodes
19{
20
24const int CVB_ERROR = static_cast<int>(CExports::CVC_E_ERROR | 0x80000000);
26const int CVB_PARAMETER = static_cast<int>(CExports::CVC_E_PARAMETER | 0x80000000);
28const int CVB_FILEIO = static_cast<int>(CExports::CVC_E_FILEIO | 0x80000000);
30const int CVB_TIMEOUT = static_cast<int>(CExports::CVC_E_TIMEOUT | 0x80000000);
32const int CVB_MEMORY = static_cast<int>(CExports::CVC_E_MEMORY | 0x80000000);
34const int CVB_INVALIDPLANE = static_cast<int>(CExports::CVC_E_INVALIDPLANE | 0x80000000);
36const int CVB_UNSUPPORTEDDATATYPE = static_cast<int>(CExports::CVC_E_UNSUPPORTEDDATATYPE | 0x80000000);
38const int CVB_INVALIDCAMERAPORT = static_cast<int>(CExports::CVC_E_INVALIDCAMERAPORT | 0x80000000);
40const int CVB_BOARDSELECT = static_cast<int>(CExports::CVC_E_BOARDSELECT | 0x80000000);
42const int CVB_INVALIDTRIGGERMODE = static_cast<int>(CExports::CVC_E_INVALIDTRIGGERMODE | 0x80000000);
44const int CVB_PROPERTYREAD = static_cast<int>(CExports::CVC_E_PROPERTYREAD | 0x80000000);
46const int CVB_PROPERTYWRITE = static_cast<int>(CExports::CVC_E_PROPERTYWRITE | 0x80000000);
48const int CVB_INVALIDPORT = static_cast<int>(CExports::CVC_E_INVALIDPORT | 0x80000000);
50const int CVB_PORTREAD = static_cast<int>(CExports::CVC_E_PORTREAD | 0x80000000);
52const int CVB_PORTWRITE = static_cast<int>(CExports::CVC_E_PORTWRITE | 0x80000000);
54const int CVB_NOIMAGE = static_cast<int>(CExports::CVC_E_NOIMAGE | 0x80000000);
56const int CVB_NOINTERFACE = static_cast<int>(CExports::CVC_E_NOINTERFACE | 0x80000000);
58const int CVB_BUSY = static_cast<int>(CExports::CVC_E_BUSY | 0x80000000);
60const int CVB_NOTSUPPORTED = static_cast<int>(CExports::CVC_E_NOTSUPPORTED | 0x80000000);
62const int CVB_GRABABORTED = static_cast<int>(CExports::CVC_E_GRABABORTED | 0x80000000);
64const int CVB_NOPIXELLIST = static_cast<int>(CExports::CVC_E_NOPIXELLIST | 0x80000000);
66const int CVB_NOTENOUGHDATA = static_cast<int>(CExports::CVC_E_NOTENOUGHDATA | 0x80000000);
68const int CVB_NOTRANSFORMATION = static_cast<int>(CExports::CVC_E_NOTRANSFORMATION | 0x80000000);
70const int CVB_LINEAR_ONLY = static_cast<int>(CExports::CVC_E_LINEAR_ONLY | 0x80000000);
72const int CVB_DIVISIONBYZERO = static_cast<int>(CExports::CVC_E_DIVISIONBYZERO | 0x80000000);
74const int CVB_INVALIDDIMENSION = static_cast<int>(CExports::CVC_E_INVALIDDIMENSION | 0x80000000);
76const int CVB_INVALIDCOLORMODEL = static_cast<int>(CExports::CVC_E_INVALIDCOLORMODEL | 0x80000000);
78const int CVB_INVALIDDATATYPE = static_cast<int>(CExports::CVC_E_INVALIDDATATYPE | 0x80000000);
80const int CVB_WRONGOBJECT = static_cast<int>(CExports::CVC_E_WRONGOBJECT | 0x80000000);
82const int CVB_NOTREADY = static_cast<int>(CExports::CVC_E_NOTREADY | 0x80000000);
84const int CVB_NOANGLE = static_cast<int>(CExports::CVC_E_NOANGLE | 0x80000000);
86const int CVB_NOVECTOR2D = static_cast<int>(CExports::CVC_E_NOVECTOR2D | 0x80000000);
88const int CVB_NOLINE2D = static_cast<int>(CExports::CVC_E_NOLINE2D | 0x80000000);
90const int CVB_VECTOR2D_ZERO_LENGTH = static_cast<int>(CExports::CVC_E_VECTOR2D_ZERO_LENGTH | 0x80000000);
92const int CVB_VECTORS_IDENTICAL = static_cast<int>(CExports::CVC_E_VECTORS_IDENTICAL | 0x80000000);
94const int CVB_LINE2D_VERTICAL = static_cast<int>(CExports::CVC_E_LINE2D_VERTICAL | 0x80000000);
96const int CVB_LINE2D_HORIZONTAL = static_cast<int>(CExports::CVC_E_LINE2D_HORIZONTAL | 0x80000000);
98const int CVB_NOARGUMENT = static_cast<int>(CExports::CVC_E_NOARGUMENT | 0x80000000);
100const int CVB_LINE2D_UNDEFINED = static_cast<int>(CExports::CVC_E_LINE2D_UNDEFINED | 0x80000000);
102const int CVB_NOINTERSECTION = static_cast<int>(CExports::CVC_E_NOINTERSECTION | 0x80000000);
104const int CVB_NOCLIPPING = static_cast<int>(CExports::CVC_E_NOCLIPPING | 0x80000000);
106const int CVB_NOTENOUGHLINES = static_cast<int>(CExports::CVC_E_NOTENOUGHLINES | 0x80000000);
108const int CVB_OVERFLOW = static_cast<int>(CExports::CVC_E_OVERFLOW | 0x80000000); // OVERFLOW clash with math.h
110const int CVB_NOCIRCLE = static_cast<int>(CExports::CVC_E_NOCIRCLE | 0x80000000);
112const int CVB_ACCESS = static_cast<int>(CExports::CVC_E_ACCESS | 0x80000000);
114const int CVB_NOTPRESENT = static_cast<int>(CExports::CVC_E_NOTPRESENT | 0x80000000);
116const int CVB_UNSUPPORTEDFEATURE = static_cast<int>(CExports::CVC_E_UNSUPPORTEDFEATURE | 0x80000000);
118const int CVB_INVALIDINDEX = static_cast<int>(CExports::CVC_E_INVALIDINDEX | 0x80000000);
120const int CVB_NOOVERLAY = static_cast<int>(CExports::CVC_E_NOOVERLAY | 0x80000000);
122const int CVB_INVALIDSTATE = static_cast<int>(CExports::CVC_E_INVALIDSTATE | 0x80000000);
124const int CVB_EMPTYRESULT = static_cast<int>(CExports::CVC_E_EMPTYRESULT | 0x80000000);
125
126
127inline int FromRes(CExports::cvbres_t hr) noexcept
128{
129 return static_cast<int>((hr) & 0x7FFFFFFF);
130}
131
132};
133
135
138 : public std::runtime_error
139{
140 public:
141
142 static std::exception_ptr FromCvbResult(int errorCode, const std::string& message) noexcept
143 {
144 switch (errorCode)
145 {
154 return std::make_exception_ptr(std::invalid_argument(message));
155
162 return std::make_exception_ptr(std::out_of_range(message));
163
164
179 return std::make_exception_ptr(std::domain_error(message));
180
181
183 return std::make_exception_ptr(std::bad_alloc());
184
186 return std::make_exception_ptr(std::overflow_error(message));
187
188 default:
189 return std::make_exception_ptr(CvbException(message, errorCode));
190
191
192 }
193 }
194
196
200 int ErrorCode() const noexcept
201 {
202 return errorCode_;
203 }
204
205 private:
206
207 CvbException(const std::string& message, int errorCode) noexcept
208 : std::runtime_error(message)
209 , errorCode_(errorCode)
210 {
211 }
212
213 int errorCode_ = 0;
214
215};
216
217CVB_END_INLINE_NS
218
219}
Special runtime exception to carry a native error code.
Definition: exception.hpp:139
int ErrorCode() const noexcept
Get the classic API error code.
Definition: exception.hpp:200
@ CVC_E_PORTREAD
A port read operation failed.
Definition: CVCError.h:97
@ CVC_E_WRONGOBJECT
At least one of the input handles points to the wrong type of object.
Definition: CVCError.h:131
@ CVC_E_OK
No Error occurred.
Definition: CVCError.h:58
@ CVC_E_MEMORY
Definition: CVCError.h:73
@ CVC_E_NOCLIPPING
No clipping points available.
Definition: CVCError.h:159
@ CVC_E_LINE2D_HORIZONTAL
The operation failed because the line object passed to it is horizontal.
Definition: CVCError.h:149
@ CVC_E_INVALIDPORT
An invalid/unavailable port was selected.
Definition: CVCError.h:95
@ CVC_E_NOTSUPPORTED
The requested feature is not supported.
Definition: CVCError.h:110
@ CVC_E_PARAMETER
Definition: CVCError.h:64
@ CVC_E_VECTOR2D_ZERO_LENGTH
Definition: CVCError.h:142
@ CVC_E_INVALIDDATATYPE
An invalid data type descriptor has been passed to the function.
Definition: CVCError.h:129
@ CVC_E_NOTPRESENT
Definition: CVCError.h:170
@ CVC_E_ERROR
Definition: CVCError.h:61
@ CVC_E_PROPERTYWRITE
Definition: CVCError.h:93
@ CVC_E_INVALIDPLANE
Definition: CVCError.h:76
@ CVC_E_NOIMAGE
Definition: CVCError.h:102
@ CVC_E_INVALIDCOLORMODEL
An invalid/undefined color model mode has been passed to the function.
Definition: CVCError.h:127
@ CVC_E_NOVECTOR2D
The input handle does not point to a valid 2D vector object.
Definition: CVCError.h:137
@ CVC_E_NOINTERFACE
Definition: CVCError.h:105
@ CVC_E_NOPIXELLIST
At least one of the input handles does not point to a valid pixel list.
Definition: CVCError.h:114
@ CVC_E_INVALIDSTATE
A state which does not allow to call a function.
Definition: CVCError.h:180
@ CVC_E_INVALIDINDEX
An index value in an indexed access exceeded its limits.
Definition: CVCError.h:175
@ CVC_E_UNSUPPORTEDFEATURE
Definition: CVCError.h:173
@ CVC_E_NOINTERSECTION
Definition: CVCError.h:157
@ CVC_E_LINE2D_UNDEFINED
Definition: CVCError.h:154
@ CVC_E_NOTENOUGHLINES
Not enough lines available to calculate the intersection reliably.
Definition: CVCError.h:161
@ CVC_E_NOOVERLAY
Definition: CVCError.h:178
@ CVC_E_DIVISIONBYZERO
A division by zero was attempted.
Definition: CVCError.h:123
@ CVC_E_EMPTYRESULT
Definition: CVCError.h:183
@ CVC_E_INVALIDTRIGGERMODE
An attempt to select and invalid/unsupported trigger mode was made.
Definition: CVCError.h:85
@ CVC_E_ACCESS
A feature access failed.
Definition: CVCError.h:167
@ CVC_E_PROPERTYREAD
Definition: CVCError.h:89
@ CVC_E_NOTENOUGHDATA
The amount of input data is insufficient for the requested operation.
Definition: CVCError.h:116
@ CVC_E_BOARDSELECT
An attempt to switch to an invalid/unavailable board was made.
Definition: CVCError.h:83
@ CVC_E_FILEIO
Definition: CVCError.h:67
@ CVC_E_OVERFLOW
An input value was too big or did lead to a too big result.
Definition: CVCError.h:163
@ CVC_E_NOTREADY
The device or object is not ready to handle the requested operation.
Definition: CVCError.h:133
@ CVC_E_GRABABORTED
The current grab operation was aborted.
Definition: CVCError.h:112
@ CVC_E_NOANGLE
The input handle does not point to a valid angle object.
Definition: CVCError.h:135
@ CVC_E_NOLINE2D
The input handle does not point to a valid 2D line object.
Definition: CVCError.h:139
@ CVC_E_LINE2D_VERTICAL
The operation failed because the line object passed to it is vertical.
Definition: CVCError.h:147
@ CVC_E_INVALIDDIMENSION
An invalid number of planes was specified.
Definition: CVCError.h:125
@ CVC_E_NOCIRCLE
The input handle does not point to a valid 2D circle object.
Definition: CVCError.h:165
@ CVC_E_UNSUPPORTEDDATATYPE
Definition: CVCError.h:79
@ CVC_E_INVALIDCAMERAPORT
An attempt to switch to an invalid/unavailable camera port was made.
Definition: CVCError.h:81
@ CVC_E_NOARGUMENT
The argument cannot be calculated for a vector of length zero.
Definition: CVCError.h:151
@ CVC_E_NOTRANSFORMATION
Definition: CVCError.h:119
@ CVC_E_LINEAR_ONLY
The function only works on images with a linear VPAT layout.
Definition: CVCError.h:121
@ CVC_E_VECTORS_IDENTICAL
Definition: CVCError.h:145
@ CVC_E_PORTWRITE
A port write operation failed.
Definition: CVCError.h:99
@ CVC_E_BUSY
Definition: CVCError.h:108
@ CVC_E_TIMEOUT
A timeout occurred in an asynchronous function call.
Definition: CVCError.h:69
const int CVB_NOANGLE
Not an angle object.
Definition: exception.hpp:84
const int CVB_INVALIDDATATYPE
Invalid data type.
Definition: exception.hpp:78
const int CVB_PROPERTYWRITE
Property write error.
Definition: exception.hpp:46
const int CVB_INVALIDCOLORMODEL
Invalid color model.
Definition: exception.hpp:76
const int CVB_NOOVERLAY
Image that is expected to have overlay bits does not have overlay bits.
Definition: exception.hpp:120
const int CVB_INVALIDSTATE
A state which does not allow to call a function.
Definition: exception.hpp:122
const int CVB_NOTENOUGHLINES
Not enough lines to perform intersection.
Definition: exception.hpp:106
const int CVB_PROPERTYREAD
Property read error.
Definition: exception.hpp:44
const int CVB_BUSY
Hardware busy.
Definition: exception.hpp:58
const int CVB_LINE2D_VERTICAL
Vertical line.
Definition: exception.hpp:94
const int CVB_DIVISIONBYZERO
Division by zero was attempted.
Definition: exception.hpp:72
const int CVB_NOCLIPPING
No clipping points available.
Definition: exception.hpp:104
const int CVB_UNSUPPORTEDDATATYPE
Unsupported data type.
Definition: exception.hpp:36
const int CVB_BOARDSELECT
Board select failed.
Definition: exception.hpp:40
const int CVB_ERROR
Generic unspecified error.
Definition: exception.hpp:24
const int CVB_NOPIXELLIST
Pointer was not pointing to a pixel list.
Definition: exception.hpp:64
const int CVB_GRABABORTED
Failure because grab was aborted.
Definition: exception.hpp:62
const int CVB_INVALIDDIMENSION
Invalid number of dimensions.
Definition: exception.hpp:74
const int CVB_INVALIDPORT
Invalid port.
Definition: exception.hpp:48
const int CVB_NOTREADY
Not ready for the requested operation.
Definition: exception.hpp:82
const int CVB_LINE2D_UNDEFINED
Line 2D object has not yet been defined.
Definition: exception.hpp:100
const int CVB_INVALIDINDEX
Index in an indexed access exceeded limits.
Definition: exception.hpp:118
const int CVB_PORTWRITE
could not write port.
Definition: exception.hpp:52
const int CVB_FILEIO
File I/O error.
Definition: exception.hpp:28
const int CVB_NOTRANSFORMATION
The object passed to the function was not a NL-transformation object.
Definition: exception.hpp:68
const int CVB_NOCIRCLE
Object is not a 2D circle.
Definition: exception.hpp:110
const int CVB_EMPTYRESULT
The function returned an empty result, e.g. nullptr for an empty point cloud.
Definition: exception.hpp:124
const int CVB_NOTENOUGHDATA
Too few data available for a calculation.
Definition: exception.hpp:66
const int CVB_INVALIDTRIGGERMODE
Invalid trigger mode.
Definition: exception.hpp:42
const int CVB_INVALIDCAMERAPORT
Invalid camera port.
Definition: exception.hpp:38
const int CVB_LINEAR_ONLY
The function only works on linear images.
Definition: exception.hpp:70
const int CVB_NOINTERSECTION
The lines provided to the function do not intersect.
Definition: exception.hpp:102
const int CVB_NOVECTOR2D
Not a 2D vector object.
Definition: exception.hpp:86
const int CVB_OK
No error occurred.
Definition: exception.hpp:22
const int CVB_PARAMETER
Parameter error.
Definition: exception.hpp:26
const int CVB_NOLINE2D
Not a 2D line object.
Definition: exception.hpp:88
const int CVB_MEMORY
Memory allocation failed.
Definition: exception.hpp:32
const int CVB_ACCESS
Access error.
Definition: exception.hpp:112
const int CVB_NOINTERFACE
Interface not available.
Definition: exception.hpp:56
const int CVB_VECTOR2D_ZERO_LENGTH
Vector has zero length.
Definition: exception.hpp:90
const int CVB_WRONGOBJECT
Wrong object.
Definition: exception.hpp:80
const int CVB_NOIMAGE
No image at all.
Definition: exception.hpp:54
const int CVB_NOTSUPPORTED
A certain feature is not supported.
Definition: exception.hpp:60
const int CVB_LINE2D_HORIZONTAL
Horizontal line.
Definition: exception.hpp:96
const int CVB_INVALIDPLANE
Invalid plane used.
Definition: exception.hpp:34
const int CVB_OVERFLOW
Input value was too big or did lead to a too big result.
Definition: exception.hpp:108
const int CVB_NOARGUMENT
Argument cannot be calculated for x = y = 0.
Definition: exception.hpp:98
const int CVB_TIMEOUT
Timeout in function.
Definition: exception.hpp:30
const int CVB_UNSUPPORTEDFEATURE
The requested feature is not supported (may happen if a specific interface implementation cannot impl...
Definition: exception.hpp:116
const int CVB_VECTORS_IDENTICAL
Identical vectors.
Definition: exception.hpp:92
const int CVB_PORTREAD
Could not read port.
Definition: exception.hpp:50
const int CVB_NOTPRESENT
Not present.
Definition: exception.hpp:114
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24