Throw Statement

Generates a program execution exception.

Throwexception_object

Prerequisites

None

Parameters

exception_object

Required Exception Object.  The Exception can contain either a general or a robot formatted error.

Remarks

This statement can be included in any procedure and need not be contained within a Try...Catch...Finally...End Try structure.  Whenever it is executed, a program exception is immediately signaled.  If this statement is not executed within a Try block, execution of the thread is terminated and the error contained within the exception_object is reported to the operator.

The Throw statement is often used within a Catch block.  If the Exception captured by the Catch is not to be processed by the Catch block, the Exception can be reissued by a Throw statement.  This allows Exceptions that are not to be serviced by a Catch to be passed to a higher-level Catch or to halt thread execution.

To allow application programs to generate their own special Exceptions, two error codes exist that are never automatically generated by the controller:

(-786) *Project generated error*
(-1038) *Project generated robot error*

These error codes can be emitted by the Throw instruction to alert the operator to special exception conditions not normally detected by GPL.

If the ErrorCode property of the Exception Object parameter is not a negative value, the error -807 "Invalid exception" is thrown. If you have just created the object, the value of ErrorCode is zero by default, so you must explicitly set it to avoid this error.

Examples

    Dim exc1 As New Exception
Try

retry:
Move.Loc(loc1, profile1)
Move.WaitForEOM
Catch exc1
If (exc1.ErrorCode = -153) Then ' Soft envelope error?
profile1.Speed *= .9 ' Yes, reduce speed
GoTo retry
End If
Throw exc1 ' Emit unknown error
End Try

See Also

Exception Handling