Sign in to follow this  
Followers 0
Joon

On Error Resume Next

6 posts in this topic

Does AutoIt have anything similar to On Error Resume Next? I have wrote script to connect to multiple databases and perform maintenances. If everything is set right, it's working great. But if one entry have bad information like invalid password, whole script stops. And it doesn't handle by COM error handler instead i just get .Open^ ERROR . So, how do I need make my script ignore error message and keep going?

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
$ado = ObjCreate("ADODB.Connection")
$file = FileOpen("config.txt", 0)
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    ; parse $line to get connection info.
    With $ado
        .ConnectionString = ("Provider='OraOLEDB.Oracle';Data Source='" & $DBSource & "';User Id='" & $UserID & "';Password='" & $Password & "';")
        .Open
    EndWith
    ; Some function here to get RecordSet
    $ado.Close
WEnd
FileClose($file)

Func MyErrFunc()
    SetError(1)
EndFunc

Share this post


Link to post
Share on other sites



My suggestion would be to add this to the top of your script.

#include <IE.au3>

_IEErrorHandlerRegister()

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

My suggestion would be to add this to the top of your script.

#include <IE.au3>

_IEErrorHandlerRegister()
Still gets an error on .Open with bad password. :P Edited by Joon

Share this post


Link to post
Share on other sites

Still gets an error on .Open with bad password. :P

Oops! Take this line out of your script.

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

Share this post


Link to post
Share on other sites

Oops! Take this line out of your script.

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")oÝ÷ Ûú®¢×¶)e}¨¥³­Æ¦yê뢹²Æ y8b²+'£!jÒ7ök^²Ø§«­¢+Ø(¥¹±Õ±Ðí%¹ÔÌÐì)}%ÉɽÉ!¹±ÉI¥ÍÑÈ ¤(ÀÌØí¼ô=©
ÉÑ ÅÕ½Ðí=¹
½¹¹Ñ¥½¸ÅÕ½Ðì¤)]¥Ñ ÀÌØí¼($¹
½¹¹Ñ¥½¹MÑÉ¥¹ô ÅÕ½ÐíAɽ٥ÈôÌäí=É=1¹=ɱÌäìíÑM½ÕÉôÌäí=IÌäìíUÍÈ%ôÌäíUÍÉ9µÌäìíAÍÍݽÉôÌäí AÍÍݽÉÌäììÅÕ½Ðì¤($¹=Á¸)¹]¥Ñ )5Í   ½à À°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðí¡±±¼ÅÕ½Ðì¤(ÀÌØí¼¹
±½Í(

I never get to MsgBox, I do get to it with a good password.

Share this post


Link to post
Share on other sites

is there no way to continue the script run if an error occured?

i searched and found this (by: Weaponx)

If you have your own error handler, place this at the top of your script Opt("RunErrorsFatal", 0) like Jos said.

If you are in a loop you can do this:

For $X = 1 to 10

$result = Ping("www.google.com")

If @ERROR Then ContinueLoop

MsgBox(0,"","Ping successful")

Next

by Jos

there is no "On Error Resume Next" option in AutoIt3, but there are 2 things that can be set:

Catching errors running a program: Opt("RunErrorsFatal", 1) ;1=fatal, 0=silent set @error

Catching COm errors:

CODE

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler

; This is my custom error handler

Func MyErrFunc()
   $HexNumber=hex($oMyError.number,8)
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Windescription is: " & $oMyError.windescription )

   SetError(1); something to check for when this function returns
EndfuncoÝ÷ Ûú®¢×º×mºw^®ËZØhÂÚ¢+fÉìZ^r^jëh×6_Showhide("Second")
_Showhide("Third")

Func _Showhide($Title)
    If WinExists($Title, "") Then
        WinSetState($Title, "", @SW_HIDE)
        MsgBox(64, "Title", "Press ok to show window.", 10)
        WinSetState($Title, "", @SW_SHOW)
        MsgBox(64, "Title", "Press ok to Close the window.", 10)
        WinClose($Title, "")
    EndIf
EndFunc  ;==>_Showhide

any help?


Unresolved topics:1- Please help me in Editing or replacing a page in FireFox and IE.Please have a look at them.

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  
Followers 0