【发布时间】:2016-03-03 21:32:24
【问题描述】:
我的 AutoIt 脚本生成了一个我想要处理的错误。任何错误都转到自定义函数的方法也可以。在 VBA 中,我使用 OnErrorGoTo,但在 AutoIt 中找不到类似的东西。
我的代码:
Func Start()
While 1
If ProcessExists ( "Photoshop.exe" ) <> 0 Then
Sleep(5000)
Else
Local $sFile ="C:\Auto\CodeToBe\Batch\Image Process-50-2D v.2-" & $n & ".jsxbin"
Local $iPID = ShellExecute($sFile)
Sleep(10000)
$n = $n+1
EndIf
WEnd
EndFunc
当$n 超过该文件夹中的文件数时会发生错误。我试过了,但没有用(来自“帮助部分”和论坛帖子):
Global $iEventError = 0 ; To be checked to know if COM error occurs. Must be reset after handling.
Local $oMyError = ObjEvent("AutoIt.Error", "ErrFunc") ; Install a custom error handler
Func Start()
While 1
If ProcessExists ( "Photoshop.exe" ) <> 0 Then
Sleep(5000)
Else
Local $sFile ="C:\Auto\CodeToBe\Batch\Image Process-50-2D v.2-" & $n & ".jsxbin"
Local $iPID = ShellExecute($sFile)
If $iEventError Then
MsgBox($MB_OK, "", "There was an error on the previous line.")
$iEventError = 0 ; Reset after displaying a COM Error occurred
EndIf
Sleep(10000)
$n = $n+1
EndIf
WEnd
EndFunc
; This is my custom error handler
Func MyErrFunc()
Msgbox(0,"","ERROR GENERATED ON " & $n)
Endfunc
【问题讨论】:
标签: error-handling autoit