Sarah2016

Skipping Errors

5 posts in this topic

Hi,

I am doing a script that do some uploading..

As you know, this script is very susceptible to errors (no internet, or the internet connection get lost during uploading large files, etc.)..

Sadly, once AutoIt Script got error it sends message and closes.

I know there are tens of posts previously on error handling..

 

I just want to make sure of my understanding..

If I placed:

If not @error then

   function code

endif

 

Will that prevent all errors in the function??

Share this post


Link to post
Share on other sites



No. Think of the @error as a special kind of variable that is normally used to provide information about why something went wrong in a function. Using it does not "do" anything - it merely contains information that you as the developer can use to control what your script does.

The only way to actually prevent an error is to write your code in such a way that the error does not occur, or that it gets handled properly. You can't just set a switch that prevents errors (that would be the holy grail of programming :) ).


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
52 minutes ago, SadBunny said:

No. Think of the @error as a special kind of variable that is normally used to provide information about why something went wrong in a function. Using it does not "do" anything - it merely contains information that you as the developer can use to control what your script does.

The only way to actually prevent an error is to write your code in such a way that the error does not occur, or that it gets handled properly. You can't just set a switch that prevents errors (that would be the holy grail of programming :) ).

Thanks SadBunny..

Question.. since the script will exist once it get an error (sometimes error are unpredictable! so I can't write code for it not to occur), is there any way to make the script run again (re-open the file) if it get and error??

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

If looping through and testing for forseeable errors I love ContinueLoop

Edited by Jury
typo

Share this post


Link to post
Share on other sites
1 hour ago, Sarah2016 said:

(sometimes error are unpredictable! so I can't write code for it not to occur)

Disagree, every AutoIt function you call has set criteria for success or failure. The number of errors you truly cannot check for are going to be minuscule. Yes, it takes more time to do it right rather than just trying to ignore errors, but it also leads to stable code. It is a snowball effect; if you're simply skipping errors because you don't want to deal with them, by the time the script barfs because it simply can't continue you'll have no idea where the errors began. Lazy coding is definitely not the way to go.


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

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