• Otherwise... the exception makes your program crash, bang!
As this latest situation is not the most desirable, the Yoctopuce library offers another possibility for
error handling, allowing you to create a robust program without needing to catch exceptions at every
line of code. You simply need to call the
YAPI.DisableExceptions()
function to commute the
library to a mode where exceptions for all the functions are systematically replaced by specific return
values, which can be tested by the caller when necessary. For each function, the name of each
return value in case of error is systematically documented in the library reference. The name always
follows the same logic: a
get_state()
method returns a
Y_STATE_INVALID
value, a
get_currentValue
method returns a
Y_CURRENTVALUE_INVALID
value, and so on. In any
case, the returned value is of the expected type and is not a null pointer which would risk crashing
your program. At worst, if you display the value without testing it, it will be outside the expected
bounds for the returned value. In the case of functions which do not normally return information, the
return value is
YAPI_SUCCESS
if everything went well, and a different error code in case of failure.
When you work without exceptions, you can obtain an error code and an error message explaining
the source of the error. You can request them from the object which returned the error, calling the
errType()
and
errMessage()
methods. Their returned values contain the same information as
in the exceptions when they are active.
11.4. Integration variants for the C++ Yoctopuce library
Depending on your needs and on your preferences, you can integrate the library into your projects in
several distinct manners. This section explains how to implement the different options.
Integration in source format
Integrating all the sources of the library into your projects has several advantages:
• It guaranties the respect of the compilation conventions of your project (32/64 bits, inclusion of
debugging symbols, unicode or ASCII characters, etc.);
• It facilitates debugging if you are looking for the cause of a problem linked to the Yoctopuce
library;
• It reduces the dependencies on third party components, for example in the case where you
would need to recompile this project for another architecture in many years;
• It does not require the installation of a dynamic library specific to Yoctopuce on the final
system, everything is in the executable.
To integrate the source code, the easiest way is to simply include the
Sources
directory of your
Yoctopuce library into your
IncludePath
, and to add all the files of this directory (including the sub-
directory
yapi
) to your project.
For your project to build correctly, you need to link with your project the prerequisite system libraries,
that is:
• For Windows: the libraries are added automatically
• For Mac OS X:
IOKit.framework
and
CoreFoundation.framework
• For Linux:
libm
,
libpthread
,
libusb1.0
, and
+
Integration as a static library
Integration of the Yoctopuce library as a static library is a simpler manner to build a small executable
which uses Yoctopuce modules. You can quickly compile the program with a single command. You
do not need to install a dynamic library specific to Yoctopuce, everything is in the executable.
To integrate the static Yoctopuce library to your project, you must include the
Sources
directory of
the Yoctopuce library into your
IncludePath
, and add the sub-directory
Binaries/...
corresponding to your operating system into your
libPath
.
11. Using Yocto-Display with C++
www.yoctopuce.com
63
Содержание Yocto-Display
Страница 1: ...Yocto Display User Manual...
Страница 2: ......
Страница 40: ...34 www yoctopuce com...
Страница 52: ...46 www yoctopuce com...
Страница 84: ...78 www yoctopuce com...
Страница 92: ...86 www yoctopuce com...
Страница 130: ...124 www yoctopuce com...
Страница 158: ...22 High level API Reference 152 www yoctopuce com On failure throws an exception or returns a negative error code...
Страница 422: ...416 www yoctopuce com...
Страница 424: ...24 Characteristics 418 www yoctopuce com...