Jump to content
Sign in to follow this  
passkalilo

How to avoid exit when error occured?

Recommended Posts

passkalilo

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

Share this post


Link to post
Share on other sites
oMBRa

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

Share this post


Link to post
Share on other sites
Jos

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

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
passkalilo

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

Share this post


Link to post
Share on other sites
nguyenbason

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

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.