A SERVICE OF

logo

BASIC Moves Development Studio 06/2005 Danaher Motion
34 Rev E M-SS-005-03l
Catch statements are used within three types of error trapping blocks.
The Try block is designed to trap synchronous errors within task context (For
more details, see the Error Handling section). There is no explicit limitation
on the number of Try blocks instances in a program. The syntax for a Try
block is:
Try
{code being examined for synchronous errors}
{Catch Error_Number
{statements to be executed}}
{Catch Is <RelationalOperator> Error_Number
{statements to be executed}}
{Catch Error_Number1 To Error_Number2
{statements to be executed}}
{Catch Else
{statements to be executed}}
{Finally
{statements to be executed if an error was trapped}}
End Try
An example of a Try block, designed to catch errors in the loading process of
Task1.Prg:
Try
Load Task1.Prg
Catch 4033 ‘ File does not exist
Print “Task not found”
Catch 6007 ‘ Task must be killed first
KillTask Task1.Prg
Unload Task1.Prg
Load Task1.Prg
Catch Else
Print “Error while loading Task1.Prg”
Finally
Print “Caught error: “ Task1.prg.Error
End Try
The OnError block is designed to trap and process both synchronous
and asynchronous errors in a task. OnError traps errors not trapped by
the Try/Finally mechanism within the task. (For more details, see “Error
Handling” section). Only one instance of OnError may exist in a
program. The syntax for OnError block is:
OnError
{Catch Error_Number
{statements to be executed}}
{Catch Is <RelationalOperator> Error_Number
{statements to be executed}}
{Catch Error_Number1 To Error_Number2
{statements to be executed}}
{Catch Else
{statements to be executed}}
End OnError