Error Handling

NI IMAQ

Error Handling

Errors generated by the CWIMAQ control have an Error Context and a Status Code associated with them. The CWIMAQErrorContext constants specify the Error Contexts. The Status Code for an error is a negative value that corresponds to the actual error that occurred.

There are three ways that errors are reported by the CWIMAQ control:

  • Return value of the methods
  • Exceptions
  • IMAQError event

The CWIMAQ.ExceptionOnError property specifies if the control throws an exception when an error occurs. If ExceptionOnError is set to False, no exception is generated. If the error was generated as a result of a method call, the method returns the status code. If ExceptionOnError is set to True, the CWIMAQ control throws an exception. If you choose to catch this exception, you can use the Err object in Visual Basic to get information about the exception that the control generated.

The CWIMAQ control generates an IMAQError event if there is an error. To select the contexts for which CWIMAQ generates error events, add the appropriate CWIMAQErrorContexts constants together and assign the sum of the constants to CWIMAQ.ErrorEventMask. The IMAQError event provides information about the status code and the context in which the error occurred

You can handle errors using one of the following methods:

  • Set ExceptionOnError to True, and do not provide an exception-handling mechanism. This directs your application to generate a run-time error and display a run-time error dialog.
  • Set ExceptionOnError to True, and provide an exception-handling mechanism. You can then direct how your application handles the exception.
  • Set ExceptionOnError to False to check the value of the return code. This method requires you to check the return values every time you make a method call and handle the return values appropriately.
  • Use the IMAQError event handler in conjunction with setting the value of ExceptionOnError to do what is appropriate for your application. This method allows you to handle errors according to the context. Also, this method allows you to identify errors that might occur during an asynchronous acquisition to handle them appropriately.