MC-Basic:TRY ... END TRY/zh-hans

From SoftMC-Wiki
< MC-Basic:TRY ... END TRY
Revision as of 09:49, 2 May 2017 by Chi (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

缩写

格式

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

适用版本

所有版本

描述

TRY ... END TRY命令是用于捕捉同步错误。同步错误是由用户任务引起的,由编译器检测到的。这种类型的错误与用户定义任务中特定的程序代码行相关联。示例中给出了在移动命令中除以零和超出范围参数。TRY模块用于进行与程序代码的特定区域相关的特定操作。它可以在OnError或OnSystemError块中使用。
可以使用User Error的.num属性捕获用户错误。

类型

取值范围

单位

默认

使用范围

任务区

限制

允许嵌套TRY块,条件是嵌套TRY仅出现在Catch块内。Catch部分允许使用GOTO指令,但引用的标签必须在该部分内。

Template:注意

例子

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

参见