Autoit 调用COM对象出错处理

来源:互联网 发布:fc2域名 编辑:程序博客网 时间:2024/05/22 12:47

 ; ObjEvent example
; COM Error Handler example
$oIE=ObjCreate("InternetExplorer.Application.1")
; Create Internet Explorer application
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
; Initialize a COM error handler
$oIE.UnknownMethod  
; Deliberately call an undefined method
If @error then
  Msgbox (0,"AutoItCOM test","Test passed:" & _
            "We got an error number: " & @error)
Else
  Msgbox (0,"AutoItCOM test","Test failed!")
Endif
Exit
; This is my custom defined error handler
Func MyErrFunc()

Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"&@CRLF&@CRLF & _
         "err.description is: " &@TAB&$oMyError.description&@CRLF& _
        "err.windescription:"  &@TAB&$oMyError.windescription&@CRLF& _
         "err.number is: "      &@TAB&hex($oMyError.number,8)&@CRLF& _
        "err.lastdllerror is: "&@TAB&$oMyError.lastdllerror&@CRLF& _
        "err.scriptline is: "  &@TAB&$oMyError.scriptline& @CRLF& _
         "err.source is: "      &@TAB&$oMyError.source&@CRLF& _
         "err.helpfile is: "    &@TAB&$oMyError.helpfile&@CRLF& _
         "err.helpcontext is: " &@TAB&$oMyError.helpcontext)
    Local $err = $oMyError.number
    If $err = 0 Then $err = -1
    SetError($err)  
    ; to check for after this function returns
Endfunc

原创粉丝点击