Exceptions

NI Vision for Visual Basic

Exceptions

Exceptions are error messages returned directly to the programming environment. Usually, exceptions are processed by displaying a default error message. The error message allows you to end the application or to enter debug mode and perform certain debugging functions. Part of the exception returned is an error number and error description, displayed as part of the error message.

Depending on the programming environment, you might be able to insert code that can catch exceptions being sent to the application and handle them in another manner. In Visual Basic, you can do this by using the On Error statement.

  • On Error Resume Next disables automatically generated error messages. The program continues running at the next line. To handle an error in this mode, you should check and process the information in the Err object in the code.

Private Sub Acquire_Click()
On Error Resume Next
CWIMAQ1.AcquireImage
If Err.Number <> 0 Then MsgBox "Acquire: " +  CStr(Err.Number)
End Sub

  • On Error GoTo disables automatically generated error messages and causes program execution to continue at a specified location in the subroutine. You can define one error handler in the subroutine.

Private Sub Acquire_Click()
On Error GoTo ErrorHandler
CWIMAQ1.AcquireImage
Exit Sub
ErrorHandler:
MsgBox "IMAQ Error: " + CStr(Err.Number)
Resume Next
End Sub

If you are not using Visual Basic, consult the documentation for the programming environment for information about handling exceptions.