Sarah2016 Posted November 30, 2016 Share Posted November 30, 2016 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?? Link to comment Share on other sites More sharing options...
SadBunny Posted November 30, 2016 Share Posted November 30, 2016 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. Link to comment Share on other sites More sharing options...
Sarah2016 Posted November 30, 2016 Author Share Posted November 30, 2016 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?? Link to comment Share on other sites More sharing options...
Jury Posted November 30, 2016 Share Posted November 30, 2016 (edited) If looping through and testing for forseeable errors I love ContinueLoop Edited November 30, 2016 by Jury typo Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted November 30, 2016 Moderators Share Posted November 30, 2016 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. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! 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