Jump to content

[Closed] Understanding AutoIt's Error Handling Mechanism


Zohar
 Share

Recommended Posts

Hello


I would like to know how to create Error Handling for scripts in AutoIt.

I would like to ask the question I have, using some example:

Let's say I have a simple function, called OpenInIE($URL).
This function opens IE, enters the URL, and does some more operations.

1 of those "more operations" in the function, may fail, and cause an AutoIt Error message box.


My question is this:
Can I make my script behave in such way, that If there was an Error, then the script will stop with the code in the function that has the error,
but will not stop the whole script?


for example,
If my script has 5 HotKeys,
and I clicked of of the HotKeys,
and that HotKey called a function that inside of it there was an error,
then I would like that HotKey execution to stop, and not harm the whole script.
(and of course, If I try to cal that HotKey again, then it will try again).


To describe it in simple words, I am looking for something like "On Error, Ignore that Error, and Resume the Main part of the Script".


I hope it's possible

Thank you
_________________________________
1 important thing:
If I do "Return" in the function that may have an error, then it will stop that function,
but it will not stop the function that called it and expects something back from it.
so "Return" won't be enough.


Of course I can start checking return values from the function that may have an error,
but I wish to simplify the script,
so that's why Return alone is not enough
(and that's why I did not start with checking returning values/returning error codes)

I would just like the function with the error, and the function who called the function with the error, to stop,
but the script generally will not stop and accept HotKeys.

Edited by Zohar
Link to comment
Share on other sites

My question is this:

Can I make my script behave in such way, that If there was an Error, then the script will stop with the code in the function that has the error,

but will not stop the whole script?

It depends, if the errors you're getting are "object" errors (like through using COM) then try putting _IEErrorHandlerRegister() at the top of your script, then run it in SciTE and see if you get anything in the output pane.

If that seems to do what you want, you can look further into COM error handlers by looking at the Obj/COM Reference portion of the HelpFile.

If the errors are you get are AutoIt errors (like if you try to reference an array that doesn't exist for example) then the answer is no - which leads us to:

Of course I can start checking return values from the function that may have an error,

but I wish to simplify the script,

so that's why Return alone is not enough

(and that's why I did not start with checking returning values/returning error codes)

You should always check your return values/error codes, it's pretty much a fundamental coding practice and shouldn't expect any script to work 100% of the time if you don't account for things to not work.

Edited by exodius
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...