passkalilo Posted June 15, 2009 Share Posted June 15, 2009 (edited) 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 June 15, 2009 by passkalilo Link to comment Share on other sites More sharing options...
oMBRa Posted June 15, 2009 Share Posted June 15, 2009 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 More sharing options...
Developers Jos Posted June 15, 2009 Developers Share Posted June 15, 2009 (edited) For catching object errors you can use the Comm Error handler as described in the Helpfile. Jos Edited June 15, 2009 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 More sharing options...
passkalilo Posted June 16, 2009 Author Share Posted June 16, 2009 (edited) 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 June 16, 2009 by passkalilo Link to comment Share on other sites More sharing options...
nguyenbason Posted June 16, 2009 Share Posted June 16, 2009 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 More sharing options...
passkalilo Posted June 21, 2009 Author Share Posted June 21, 2009 Very Good, Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now