Jump to content

How to avoid exit when error occured?


Recommended Posts

When my script dealing with some unexpecting factor , It is exit with a messagebox "autoit error" , How to avoid this ?

I know in C# , these problem is solved by try...catch , Does autoit have similar function ?

I tried AdlibEnable function , but it doesn't work

the following code:

$oImgs = _IEImgGetCollection ($oIE);
    For $oImg In $oImgs
        ConsoleWrite($oImg.src & @crlf)
        if StringInStr($oImg.src,"captchas") then ExitLoop
    Next
    $oPic = $oIE.document.body.createControlRange()
    $oPic.Add($oImg)
    $oPic.execCommand("Copy")

C:\Documents and Settings\Administrator\??\????\system\AutoRegister.au3 (207) : ==> ??????(?????).:

$oPic.Add($oImg)

$oPic.Add($oImg)^ ERROR

Edited by passkalilo
Link to comment
Share on other sites

you have to use If-Endif:

$oImgs = _IEImgGetCollection ($oIE);
If IsObj($oImgs) Then
    For $oImg In $oImgs
        ConsoleWrite($oImg.src & @crlf)
        if StringInStr($oImg.src,"captchas") then ExitLoop
    Next
    $oPic = $oIE.document.body.createControlRange()
    $oPic.Add($oImg)
    $oPic.execCommand("Copy")
EndIf
Link to comment
Share on other sites

  • Developers

For catching object errors you can use the Comm Error handler as described in the Helpfile.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

you have to use If-Endif:

$oImgs = _IEImgGetCollection ($oIE);
If IsObj($oImgs) Then
    For $oImg In $oImgs
        ConsoleWrite($oImg.src & @crlf)
        if StringInStr($oImg.src,"captchas") then ExitLoop
    Next
    $oPic = $oIE.document.body.createControlRange()
    $oPic.Add($oImg)
    $oPic.execCommand("Copy")
EndIf
change to this:

For $oImg In $oImgs
        ConsoleWrite($oImg.src & @crlf)
        if StringInStr($oImg.src,"captchas") then ExitLoop
    Next
                if Isobj($oimg) then return 0
    $oPic = $oIE.document.body.createControlRange()
    $oPic.Add($oImg)
    $oPic.execCommand("Copy")

Maybe I should use this option

AutoItOpt("RunErrorsFatal",0)

to avoid hard crash if error occurred.

Edited by passkalilo
Link to comment
Share on other sites

Global $g_eventerror = 0 ; to be checked to know if com error occurs. Must be reset after handling.
$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ; Install a custom error handler


; This is my custom 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
    
    $g_eventerror = $err  ; to check for after this function returns
EndFunc   ;==>MyErrFunc

UnderWorldVN- Just play the way you like it
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...