Difference between revisions of "MC-Basic:TRY ... END TRY"
(Created page with '{{MC-Basic |SHORT FORM= |SYNTAX= Try ''‘ Start of Try block<br> <nowiki><code being Terminaled></nowiki><br> ''{''Catch <Err…') |
|||
(11 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{Languages|MC-Basic:TRY_..._END_TRY}} | ||
{{MC-Basic | {{MC-Basic | ||
|SHORT FORM= | |SHORT FORM= | ||
Line 8: | Line 9: | ||
''{''Catch <Error Number X><br> | ''{''Catch <Error Number X><br> | ||
<nowiki><code to execute when error X occurs></nowiki>'' }''<br> | <nowiki><code to execute when error X occurs></nowiki>'' }''<br> | ||
− | ''{''Catch < | + | ''{''Catch <MyError.num><br> |
− | <nowiki><code to execute when | + | <nowiki><code to execute when MyError occurs ></nowiki>'' }''<br> |
''{''Catch Else<br> | ''{''Catch Else<br> | ||
{code to catch allother errors} }<br> | {code to catch allother errors} }<br> | ||
Line 20: | Line 21: | ||
|DESCRIPTION= | |DESCRIPTION= | ||
− | 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. | + | 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.<br> |
+ | Can catch user errors using .num property of User Error. | ||
|TYPE= | |TYPE= | ||
Line 40: | Line 42: | ||
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. | 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|If the catch clause throws itself again, it should not be caught by "Catch Else" or "Finally"instructions.}} | ||
+ | |EXAMPLE= | ||
+ | <syntaxhighlight lang="vb"> | ||
+ | common shared appError1 as error "Application error" 20561 | ||
+ | |||
+ | program | ||
+ | |||
+ | try | ||
+ | ' come code | ||
+ | catch 8001 | ||
+ | ' division by zero | ||
+ | catch appError1.num | ||
+ | Print "Application error" | ||
+ | |||
+ | end try | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | end | + | end program |
+ | </syntaxhighlight> | ||
|SEE ALSO= | |SEE ALSO= | ||
− | * [[ | + | * [[MC-Basic:ONERROR|ONERROR]] |
− | * [[ | + | * [[MC-Basic:ONSYSTEMERROR|ONSYSTEMERROR]] |
− | + | * [[MC-Basic:error.MSG|error.MSG]] | |
+ | * [[MC-Basic:error.NUM|error.NUM]] | ||
+ | [[Category:MC-Basic:Error Handling|TRY ... END TRY]] | ||
}} | }} |
Latest revision as of 09:44, 2 May 2017
Language: | English • 中文(简体) |
---|
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.
Can catch user errors using .num property of User Error.
Syntax
Try ‘ Start of Try block
<code being Terminaled>
{Catch <Error Number X>
<code to execute when error X occurs> }
{Catch <MyError.num>
<code to execute when MyError 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 | |
If the catch clause throws itself again, it should not be caught by "Catch Else" or "Finally"instructions. |
Examples
common shared appError1 as error "Application error" 20561
program
try
' come code
catch 8001
' division by zero
catch appError1.num
Print "Application error"
end try
end program