Neoborn Posted May 15, 2006 Share Posted May 15, 2006 Can someone explain to me the benefit of using @error over if blah <> 1 then msgbox "blahblahblha"? I don't quite understand and am in need of putting some error handling into my script. Thanks Neoborn ~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT Link to comment Share on other sites More sharing options...
Thelazytech2 Posted May 15, 2006 Share Posted May 15, 2006 Not sure exactly what you are asking, but most functions have returned codes of various error levels. The error level is not necessarily an error; it really depends upon what is meant. You can find out what a functions error code is by examining the help file. In other words @error is only as useful as the function it follows designed it to be. I know you think that I know I understand what you said, but I am not sure that what I understood is what you thought. Link to comment Share on other sites More sharing options...
Busti Posted May 15, 2006 Share Posted May 15, 2006 if you make : $move = FileMove("C:\" , "D:\" ) if @error = 1 then exit endif an error occured, the function set the error to 1 SetError(1) if you make : $move = FileMove("C:\" , "D:\" ) if $move <> 1 then exit endif the return value of $move equals not 1 that means an error happend that looks like this : SetError(1) ; @error = 1 Return 0 ; $move = 0 hope ya understand My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity Link to comment Share on other sites More sharing options...
Neoborn Posted May 15, 2006 Author Share Posted May 15, 2006 Do they not essentially say the same thing? I have Func CreateDir() DirCreate("C:\temp") If DirCreate("C:\temp") <> 1 Then MsgBox(4096, "Error", "Failed To Create Directory ""temp""...", 15) EndIf EndFunc Is that not the same as: DirCreate("C:\temp") If @error = 1 Then MsgBox(4096, "Error", "Failed To Create Directory ""temp""...", 15) EndIf Also does the exit just exit out of that func? Thanks guys ~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT Link to comment Share on other sites More sharing options...
Busti Posted May 15, 2006 Share Posted May 15, 2006 Func CreateDir() If DirCreate("C:\temp") <> 1 Then MsgBox(4096, "Error", "Failed To Create Directory ""temp""...", 15) EndIf EndFunc 1. this is enough 2. sometimes @error = 4027 or some other number, check TCP @error's My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity Link to comment Share on other sites More sharing options...
Neoborn Posted May 15, 2006 Author Share Posted May 15, 2006 (edited) lol can you answer my questions? Do they not essentially say the same thing? I have Func CreateDir() DirCreate("C:\temp") If DirCreate("C:\temp") <> 1 Then MsgBox(4096, "Error", "Failed To Create Directory ""temp""...", 15) EndIf EndFunc Is that not the same as: DirCreate("C:\temp") If @error = 1 Then MsgBox(4096, "Error", "Failed To Create Directory ""temp""...", 15) EndIf Also does the exit just exit out of that func? Thanks guys Edited May 15, 2006 by Neoborn ~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT Link to comment Share on other sites More sharing options...
Neoborn Posted May 16, 2006 Author Share Posted May 16, 2006 Also how do you make it so the next function doesn't run until the last one has completed? ~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT Link to comment Share on other sites More sharing options...
Valuater Posted May 16, 2006 Share Posted May 16, 2006 1 Do they not essentially say the same thing?no... because in the first example you have DirCreate("C:\temp") If DirCreate("C:\temp") <> 1 Then it should be If DirCreate("C:\temp") <> 1 Then then they are very close to the same 2 Is that not the same as: yes... after the fix i stated above... also this is a "preferred" way 3 Also does the exit just exit out of that func?"Exit"... ALWAYS exits/ends the script/program... to leave a function, use "Return" 4 Also how do you make it so the next function doesn't run until the last one has completed? the next function should not execute, until the current function is completed, by way of finishing, returning early, or other intervention 8) Link to comment Share on other sites More sharing options...
Neoborn Posted May 16, 2006 Author Share Posted May 16, 2006 1. So @error is the better way / standard / coding practices? 2. What is the best way to go through a bunch of functions then I currently have them function1() function2() function3() and I am presuming by this they will run one after the other sequentially, is this correct? Waht if function2 takes longer, does that matter because function3 won't run until function2 is complete? Thanks Val. ~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT Link to comment Share on other sites More sharing options...
Valuater Posted May 16, 2006 Share Posted May 16, 2006 1yes2yes3Waht if function2 takes longer, does that matter because function3 won't run until function2 is complete?function 3 WILL wait for function 2 no matter how long it takes8) Link to comment Share on other sites More sharing options...
Neoborn Posted May 16, 2006 Author Share Posted May 16, 2006 (edited) kewlio, you rox dood ty much. And btw thank you for auto123 it rox as well. Not finished it yet though <3 Would you put error handling all the way through? on every func? Edited May 16, 2006 by Neoborn ~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT Link to comment Share on other sites More sharing options...
Valuater Posted May 16, 2006 Share Posted May 16, 2006 Welcome 8) Link to comment Share on other sites More sharing options...
MHz Posted May 16, 2006 Share Posted May 16, 2006 1. So @error is the better way / standard / coding practices?Not preferred. Using Booleans is far more easier and efficient then using @error. @error should be used when a Boolean is unsuitable for a functions return value. If DirCreate("C:\temp") Then Using Booleans also allow easier operator usage. Any UDFs that I create, use @error as a last resort. Link to comment Share on other sites More sharing options...
Valik Posted May 16, 2006 Share Posted May 16, 2006 Not preferred. Using Booleans is far more easier and efficient then using @error. @error should be used when a Boolean is unsuitable for a functions return value. If DirCreate("C:\temp") Then Using Booleans also allow easier operator usage. Any UDFs that I create, use @error as a last resort. You're confusing terminology. The @error macro can be used as a boolean, too, and in fact it should be unless there is a specific need to test the value of @error. Using something as a boolean simply means you rely on the language to interpret the value to either true or false rather than explicitly comparing it to another value. The below fragment is a boolean just like your example: If 1 Then To the OP, return values are used to signal a functions success or failure. In the event there is more than one way to fail but only one valid return value for failure, then @error can be used to store a separate value useful for identifying the specific cause of failure. Lastly, there may not be a return value suitable to use for a failure value so in that case @error is used as the sole mechanism for signaling an error. Whichever method the function uses will be documented. There is no "this way is better than that way" for detecting errors with functions because not all functions can use the same method. You read the documentation to see how the function will behave and then you write code to handle what it says it might do. Don't fall into the trap that others do and assume every function will set @error on failure and try to write lazy code of checking only @error. Do what's relevant for the function at hand and nothing more or less. Link to comment Share on other sites More sharing options...
Neoborn Posted May 16, 2006 Author Share Posted May 16, 2006 Is this the best way then? DirCreate("C:\temp") If @error = 1 Then MsgBox(4096, "Error", "Failed To Create Directory ""temp""...", 15) EndIf ~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT Link to comment Share on other sites More sharing options...
Valik Posted May 16, 2006 Share Posted May 16, 2006 Is this the best way then? DirCreate("C:\temp") If @error = 1 Then MsgBox(4096, "Error", "Failed To Create Directory ""temp""...", 15) EndIfDid you even read my post? Link to comment Share on other sites More sharing options...
Neoborn Posted May 16, 2006 Author Share Posted May 16, 2006 (edited) I did skim it but I felt out of place intervening in your geek speak and the symantics of the programming language with the other fellow . If you could put it into simple man words I could probably assimilate it.The @error macro can be used as a boolean, too, and in fact it should be unless there is a specific need to test the value of @error. = Always use @error unless you need to test the value of @error...yes?There is no "this way is better than that way" for detecting errors with functions because not all functions can use the same method.= Ahh ok kewl so if the documentation says "Returns 1 if success and 0 if fail then I can just use the @error fineYou read the documentation to see how the function will behave and then you write code to handle what it says it might do.= Can you give me an example from the help file where you would use @error and where you would not?Don't fall into the trap that others do and assume every function will set @error on failure and try to write lazy code of checking only @error. Do what's relevant for the function at hand and nothing more or less.= OK, in the cases above with my dircreate example what would you use? Edited May 16, 2006 by Neoborn ~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT Link to comment Share on other sites More sharing options...
Valik Posted May 16, 2006 Share Posted May 16, 2006 I did skim it but I felt out of place intervening in your geek speak and the symantics of the programming language with the other fellow . If you could put it into simple man words I could probably assimilate it.Is English not your primary language? That was English, not "geek speak". It doesn't come much simpler than how I put it.= Always use @error unless you need to test the value of @error...yes?Qualify this statement. I'm still under the impression that you are looking for an answer along the lines of "always do this in this scenario" and that is simply not the answer. That answer does not exist. Every function has to be viewed seperate from every other function to determine the best method for handling it's failures.= Ahh ok kewl so if the documentation says "Returns 1 if success and 0 if fail then I can just use the @error fineWhat on earth makes you say such a ridiculous thing? Did you even read my post above?= Can you give me an example from the help file where you would use @error and where you would not?I would use @error on functions where I couldn't detect the failure condition in any other way. I wouldn't use it on functions that I could unless I had a need for the @error value specifically.= OK, in the cases above with my dircreate example what would you use? I would use the return value exactly like several thousand people have demonstrated above. Link to comment Share on other sites More sharing options...
Neoborn Posted May 16, 2006 Author Share Posted May 16, 2006 Thank you Valik, I still don't quite understand but you're just too smart and I'm too stupid to understand you. I'll ask th.meger over messenger, it'll be easier that way. Thank you for your effort and if other people understand then you gone and done good! ~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT 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