![]() | ReturnOnError Macro |
Returns from the current function using the supplied status parameter as the return value, if that parameter represents a failure status.
#define ReturnOnError(status)
[in] ViStatus variable to test.
This macro is useful for organizing a series of function calls that use ViStatus values as their return codes. It allows code to be written more "linearly", as opposed to using a series of nested if-else constructs.
The following example demonstrates use of the ReturnOnError macro.
ViStatus _VI_FUNC acme4321_ConfigureSweep(ViSession Vi, ViReal64 StartFrequency, ViReal64 StopFrequency) { // ... auto status = VI_SUCCESS; status = viPrintf(GetVisaSession(Vi), "CONFIG:SWE %0.15lg,%0.15lg\n", StartFrequency, StopFrequency); ReturnOnError(status); // ... }