User`s guide

82 Agilent VISA User’s Guide
3 Programming with VISA
Exception Events
An alternative to trapping VISA errors by checking the
return status after each VISA call is to use the VISA
exception event. On sessions where an exception event
handler is installed and VI_EVENT_EXCEPTION is enabled,
the exception event handler is called whenever an error
occurs while executing an operation.
Exception Handling Model
The exception- handling model follows the event- handling
model for callbacks, and it uses the same operations as
those used for general event handling. For example, an
application calls viInstallHandler and viEnableEvent to
enable exception events. The exception event is like any
other event in VISA, except that the queueing and suspended
handler mechanisms are not allowed.
When an error occurs for a session operation, the exception
handler is executed synchronously. That is, the operation
that caused the exception blocks until the exception handler
completes its execution. The exception handler is executed
in the context of the same thread that caused the exception
event.
When invoked, the exception handler can check the error
condition and instruct the exception operation to take a
specific action. It can instruct the exception operation to
continue normally (by returning VI_SUCCESS) or to not
invoke any additional handlers in the case of handler
nesting (by returning VI_SUCCESS_NCHAIN).
As noted, an exception operation blocks until the exception
handler execution is completed. However, an exception
handler sometimes may prefer to terminate the program
prematurely without returning the control to the operation
generating the exception. VISA does not preclude an
application from using a platform- specific or
language- specific exception handling mechanism from within
the VISA exception handler.