Difference between revisions of "MC-Basic:TRY ... END TRY"

From SoftMC-Wiki
Jump to: navigation, search
Line 56: Line 56:
  
 
|SEE ALSO=
 
|SEE ALSO=
* [[Axystems:MC-Basic:ONERROR|ONERROR]]
+
* [[MC-Basic:ONERROR|ONERROR]]
 
* [[Axystems:MC-Basic:ONSYSTEMERROR|ONSYSTEMERROR]]
 
* [[Axystems:MC-Basic:ONSYSTEMERROR|ONSYSTEMERROR]]
  
 
[[Category:Axystems:MC-Basic:Error Handling|TRY ... END TRY]]
 
[[Category:Axystems:MC-Basic:Error Handling|TRY ... END TRY]]
 
}}
 
}}

Revision as of 08:39, 22 May 2014

TRY…END TRY is used to trap synchronous errors. A synchronous error is one caused by the user task and detected by the interpreter. This type of error is associated with a specific line of program code in the user-defined task. Examples include division by zero and out of range parameters in a move command. The TRY block is used to take specific action with relation to a particular area of the program code. It may be used within an OnError or OnSystemError block.

Syntax

Try             ‘ Start of Try block
       <code being Terminaled>
       {Catch <Error Number X>
                   <code to execute when error X occurs> }
       {Catch <Error Number Y>
                   <code to execute when error Y occurs> }
       {Catch Else
                   {code to catch allother errors} }
       {Finally
                   <code to execute only if error occurred and was trapped> }
End Try                  ‘ End Try block

Availability

All versions

Scope

Task

Limitations

Nesting of TRY blocks is allowed on condition that the nested TRY appears only within the Catch block. The GOTO instruction is allowed within a Catch section, but the referenced label must be within that section.

NOTE-Info.svgNOTE
If the catch clause throws itself again, it should not be caught by "Catch Else" or "Finally"instructions.

Examples

Try
       Sercos.Phase = 4                     'Bring ring all the way up
       catch 12030     'Sercos ring is broken
                   print "No SERCOS: All axes are simulated"
                   a1.simulated = 1
                   a2.simulated = 1
                   a3.simulated = 1
                   a4.simulated = 1
                   a5.simulated = 1

end try

See Also