Method运行错误(非语法错误)的处理
Debug及其处理
Reset
--删除记录表格
Protocol.delete
Generator触发的Method
cycle:=cycle+1
if cycle>3
cycle:=1
end
switch cycle
case 1
B1.cont.move(S1)
case 2
B2.cont.move(S1)
case 3
B3.cont.move(S1)
end
--如果B1/B2/B3.cont为Void,即为空,那么就会弹出Debug窗口
--在Method的user-defined新建了ErrorHandler方法,此时不会弹出Debug窗口
--会继续执行ErrorHandler方法
Method对应的Debug处理
param byref error: string,
method_path: string,
line_number: integer
--记录错误
protocol.writeRow(1,protocol.yDim+1,eventController.simTime,
"Transfer failed cycle:"+num_to_str(cycle))
--退出错误状态
error:=""
ErrorHandler(SimTalk)的使用
param byref error: string,
method_path: string,
line_number: integer
if error = "«error_to_catch»"
error := "" -- assigning an empty string prevents Plant Simulation from opening the debugger
return
end
-- forward an error to the calling method
if copy(error, 1, 18) /= "Unhandled error in"
error := to_str("Unhandled error in '", method_path, "': ", error)
end
异常处理允许对方法中发生的运行时错误(非语法错误)做出处理,例如记录错误或者采取措施
对于Method,创建一个用户定义属性(类型为method或者object)或者在其Frame中创建一个属性,命名为ErrorHandler
对于用户定义为method的属性,在相同的object中再创建一个属性(类型为method或者object),命名为ErrorHandler
param byref error: string,
method_path: string,
line_number: integer -> any
if error = "Division by zero."
error := "" -- catch this error
return 1e300 -- return a value to the calling method
end
-- route error message to the calling method
error := "error in " + method_path + ": " + error
在异常处理期间如果发生另一个运行错误,不会重复执行该异常处理方法