karolisk Posted September 1, 2009 Share Posted September 1, 2009 (edited) Hi All, I'm not so pro in autoit so I do not expect that I will be able to handle all the errors. So if error happens I want script to exit quietly (without popup error message or it to close automatically). (My script is reading some data from database and performing some actions with IE.) (After some time, I will be checking if my script is not running restarting it.) Please let me know if there is a way to do that, thanks. Edited September 1, 2009 by karolisk Link to comment Share on other sites More sharing options...
jvanegmond Posted September 1, 2009 Share Posted September 1, 2009 In AutoIt it's very simple to handle errors. Everyone can write "error free" code. I'll give you a quick "tutorial" to writing error free code. If you have a funciton and you think it might fail ( you can also see if it can fail in the help file ) Then put this after the function: If @error Then Exit For example: $hWnd = WinGetHandle("omglol") If @error Then Exit If you are working with arrays you need to add a few checks with UBound. But we'll get to that later. Congratulations, you can now write error free code. And that's all there is to it! If you have any specific questions, please come back later. github.com/jvanegmond Link to comment Share on other sites More sharing options...
Rishav Posted September 1, 2009 Share Posted September 1, 2009 i think he is talking about getting error in the application being automated. like an unhandled exception dialog in .NET. the way i handle it is that i have a function where i have written the window headers for all the usual errors that i get. whenever any of these windows exist, my script takes a screenshot, logs what was the last action done and exits. i just call this function after every button click, control interaction etc. Link to comment Share on other sites More sharing options...
karolisk Posted September 1, 2009 Author Share Posted September 1, 2009 (edited) thanks for help, but I know how to handle errors with '@error'. I want to know what to do if unhandled error pops up so that my script doesn't get stuck and exit (or even better - restart ). Edited September 1, 2009 by karolisk Link to comment Share on other sites More sharing options...
jvanegmond Posted September 1, 2009 Share Posted September 1, 2009 Why would you want to do that now that you can write error free code? github.com/jvanegmond Link to comment Share on other sites More sharing options...
karolisk Posted September 1, 2009 Author Share Posted September 1, 2009 You can't handle all errors (like COM errors) so simply, just by checking '@error' (I'm using this technique). OK, there are other ways to handle them, but 'what if'. I want to be 100% sure that it doesn't get stuck even if I miss something and something goes wrong. And one more reason: I'm lazy . It would be MUCH easier and faster to write code without so much error handling. (I need to learn MUCH to write a good error proof code and I need my script to work reliably now.) It would be a nice way to avoid many problems if its possible. So, is it possible? Link to comment Share on other sites More sharing options...
Juvigy Posted September 1, 2009 Share Posted September 1, 2009 "MUCH easier and faster to write code without so much error handling." I dont think it is possible. That is why debuggers , beta testers and so on exist . You cant write a foolproof software so easily. Link to comment Share on other sites More sharing options...
karolisk Posted September 1, 2009 Author Share Posted September 1, 2009 Maybe I should just run one more simple bot in a background which would just press 'OK' button when error pops up? Link to comment Share on other sites More sharing options...
jvanegmond Posted September 1, 2009 Share Posted September 1, 2009 You can't handle all errors (like COM errors) so simply, just by checking '@error' (I'm using this technique). OK, there are other ways to handle them, but 'what if'. I want to be 100% sure that it doesn't get stuck even if I miss something and something goes wrong. If you want to handle COM errors, you do it like this: expandcollapse popup; COM Error Handler example ; ------------------------- $oIE=ObjCreate("InternetExplorer.Application.1") ; Create Internet Explorer application Global $g_eventerror = 0 ; to be checked to know if com error occurs. Must be reset after handling. $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Initialize a COM error handler $oIE.UnknownMethod ; Deliberately call an undefined method If $g_eventerror then $g_eventerror = 0 Msgbox (0,"AutoItCOM test","Test passed: We got an error number: " & @error) Else Msgbox (0,"AutoItCOM test","Test failed!") Endif Exit ; This is my custom defined error handler Func MyErrFunc() Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & hex($oMyError.number,8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) Local $err = $oMyError.number If $err = 0 Then $err = -1 $g_eventerror = $err ; to check for after this function returns Endfunc It would be a nice way to avoid many problems if its possible. So, is it possible? No, it's not possible because it would be redundant. The best way avoid problems is to write code with error checking in the right places. github.com/jvanegmond Link to comment Share on other sites More sharing options...
karolisk Posted September 1, 2009 Author Share Posted September 1, 2009 (edited) I tried to put COM handler already, but I get another error then. So I will have to dig deeper into this... or get back to my plan and try to make another background bot.No, it's not possible because it would be redundant. The best way avoid problems is to write code with error checking in the right places.I don't see how hiding error popup is redundant. And yes, I don't argue with you that its best. But at the moment I just need a result - never stucking bot.Here is text of error popup, I want to suspend, in case someone don't understand about what I'm talking about.---------------------------AutoIt Error---------------------------Line -1:Error: The requested action with this object has failed.---------------------------OK --------------------------- Edited September 1, 2009 by karolisk Link to comment Share on other sites More sharing options...
Juvigy Posted September 1, 2009 Share Posted September 1, 2009 Did you try the "COM Error Handler example" ? Post the code where you receive the error. Link to comment Share on other sites More sharing options...
karolisk Posted September 1, 2009 Author Share Posted September 1, 2009 (edited) well I tried it in a bit different way. now I see that probably my problem was because I called $ie = _IECreate ("http://onesurvey.com/Voxco.Web/", 1, 1, 1) after $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Initialize a COM error handler but why?? Edited September 1, 2009 by karolisk Link to comment Share on other sites More sharing options...
WolfWorld Posted September 1, 2009 Share Posted September 1, 2009 well I tried it in a bit different way. now I see that probably my problem was because I called $ie = _IECreate ("http://onesurvey.com/Voxco.Web/", 1, 1, 1) after $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Initialize a COM error handler but why?? It should not make a different. Main project - Eat Spaghetti - Obfuscate and Optimize your script. The most advance add-on.Website more of GadGets! Link to comment Share on other sites More sharing options...
karolisk Posted September 1, 2009 Author Share Posted September 1, 2009 well, if I do this: #include <IE.au3> Global $oMyError = ObjEvent("AutoIt.Error","errHandler") $ie = _IECreate ("http://google.com", 0, 1, 1) Exit it calls "errHandler". Link to comment Share on other sites More sharing options...
WolfWorld Posted September 1, 2009 Share Posted September 1, 2009 well, if I do this: #include <IE.au3> Global $oMyError = ObjEvent("AutoIt.Error","errHandler") $ie = _IECreate ("http://google.com", 0, 1, 1) Exit it calls "errHandler". Because an error has happen, I meant to say that it does not make a different as long as AutoIt.Error is before the error. Main project - Eat Spaghetti - Obfuscate and Optimize your script. The most advance add-on.Website more of GadGets! Link to comment Share on other sites More sharing options...
karolisk Posted September 1, 2009 Author Share Posted September 1, 2009 ok, so now why is this error happening? Link to comment Share on other sites More sharing options...
WolfWorld Posted September 1, 2009 Share Posted September 1, 2009 (edited) I don't have any problem. Everything open just fine (Win7 RTM X86) Edited September 1, 2009 by WolfWorld Main project - Eat Spaghetti - Obfuscate and Optimize your script. The most advance add-on.Website more of GadGets! Link to comment Share on other sites More sharing options...
jvanegmond Posted September 1, 2009 Share Posted September 1, 2009 The IE library is extensively error checked, including COM error checked. Any errors from the IE library will not hard crash your application. github.com/jvanegmond Link to comment Share on other sites More sharing options...
Juvigy Posted September 1, 2009 Share Posted September 1, 2009 Try this one : _IEErrorHandlerRegister("MyErrFunc") $ie = _IECreate ("http://google.com", 0, 1, 1) Exit Func MyErrFunc() ;$oError =$$oIEErrorHandler.description EndFunc ;==>MyErrFunc IE has its own error handler. Link to comment Share on other sites More sharing options...
karolisk Posted September 2, 2009 Author Share Posted September 2, 2009 I don't have any problem. Everything open just fine (Win7 RTM X86) well, but it does here. Maybe I will look into this problem when my script will be 'error handled' in other way. Try this one : _IEErrorHandlerRegister("MyErrFunc") $ie = _IECreate ("http://google.com", 0, 1, 1) Exit Func MyErrFunc() ;$oError =$$oIEErrorHandler.description EndFunc ;==>MyErrFunc IE has its own error handler. I tried this already but didn't feel much effect. thanks for help all. For now, I will make second script which will be handling error and restarting script. 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