Jump to content

An option to always handle @error ?


LondonNDIB
 Share

Recommended Posts

I'm writing a new script to automate a repetitive web process I have to go through when shipping orders out. The thing is, I'm relying on website that may change... and since potentially sensitive information is being passed, I'd like the script to halt on any @error conditions.

is there a global way of doing this rather than checking after each function?

Eg... do I have to do this?

$oIE = _IECreate ( "https://www.somesite.de/admin" )

If @error Then FooBar ( @ScriptLineNumber & " - " & @error )

$oForm = _IEFormGetObjByName ( $oIE, "login" )

If @error Then FooBar ( @ScriptLineNumber & " - " & @error )

$oUsername = _IEFormElementGetObjByName ( $oForm, "admin_name" )

If @error Then FooBar ( @ScriptLineNumber & " - " & @error )

$oPassword = _IEFormElementGetObjByName ( $oForm, "admin_pass" )

If @error Then FooBar ( @ScriptLineNumber & " - " & @error )

$oSubmit = _IEGetObjByName ($oIE, "submit")

If @error Then FooBar ( @ScriptLineNumber & " - " & @error )

_IEFormElementSetValue ( $oUsername, "test" )

If @error Then FooBar ( @ScriptLineNumber & " - " & @error )

_IEFormElementSetValue ( $oPassword, "passwrd" )

If @error Then FooBar ( @ScriptLineNumber & " - " & @error )

_IEAction ( $oSubmit, "click" )

If @error Then FooBar ( @ScriptLineNumber & " - " & @error )

_IELoadWait ( $oIE )

If @error Then FooBar ( @ScriptLineNumber & " - " & @error )

_IENavigate ( $oIE, "https://www.somesite.de/admin/somepage" )

If @error Then FooBar ( @ScriptLineNumber & " - " & @error )

;_IEAction ( $oIE, "printdefault" )

If @error Then FooBar ( @ScriptLineNumber & " - " & @error )

_IENavigate ( $oIE, "https://www.somesite.de/admin/someotherpage" )

If @error Then FooBar ( @ScriptLineNumber & " - " & @error )

$oAddress = _IEGetObjById ( $oIE, "address_field_for_auto_process" )

If @error Then FooBar ( @ScriptLineNumber & " - " & @error )

$address = _IEPropertyGet ( $oAddress, "innertext" )

If @error Then FooBar ( @ScriptLineNumber & " - " & @error )

[... etc etc etc...]

Or is there an easier way without having to inter-lace the lines with my @error check.

Thanks!

LD

Link to comment
Share on other sites

I'm writing a new script to automate a repetitive web process I have to go through when shipping orders out. The thing is, I'm relying on website that may change... and since potentially sensitive information is being passed, I'd like the script to halt on any @error conditions.

is there a global way of doing this rather than checking after each function?

Eg... do I have to do this?

Or is there an easier way without having to inter-lace the lines with my @error check.

Thanks!

LD

Maybe stick your
If @error Then FooBar ( @ScriptLineNumber & " - " & @error )
line in an AdLib function? It's not foolproof, because AdLib is only called every so many x milliseconds (defined in the AdlibEnable() function), but it might point you in the right direction... Edited by james3mg
"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
Share on other sites

Yeah, thanks. I had thought of that, but like you said... the per x ms is a problem unless I can control how many lines per ms were processed.

So far my "solution" has been to write a 2nd script that pre-compiles the first one and adds the line in every 2nd line of code :)

- Steven

Link to comment
Share on other sites

  • Moderators

Yeah, thanks. I had thought of that, but like you said... the per x ms is a problem unless I can control how many lines per ms were processed.

So far my "solution" has been to write a 2nd script that pre-compiles the first one and adds the line in every 2nd line of code :)

- Steven

You could always just write a wrapper for each function, that way you only have to write one line of code for how ever many times you call it.
$oIE = _IECreate (1, "https://www.somesite.de/admin" )
$oForm = _IEFormGetObjByName (2, $oIE, "login" )

Func __IECreate($nLineNum, $s_URL = "about:blank", $f_tryAttatch = 0, $f_Visible = 1, $f_Wait = 1, $f_takeFocus = -1)
    LOCAL $__oIE = __IECreate($s_URL, $f_tryAttatch, $f_Visible, $f_Wait, $f_takeFocus)
    If @error Then FooBar($nLineNum & " - " & @error)
    Return $__oIE
EndFunc

Func __IEFormGetObjByName(etc...)
EndFunc

The problem you are going to run into is that if it is an error, that you have no conditions set per line to stop it from continuing.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

ObjEvent() handles COM event errors so one function handles all errors. Look in the help file for _IEErrorHandlerRegister() which may give you some tips to usage. Not sure if it is registered automatically or not by using IE.au3. The error handler example will return line number that the error happened on etc.

:)

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...