DuncanM Posted October 30, 2006 Share Posted October 30, 2006 I'm in the process of writing a script to automate the browser-based configuration of a network device. As part of this, there are a lot of object references to forms/buttons, button clicks, etc. So, my question is, what is the best way to implement error handling? I'm eventually going to be turning this over to end users who have no AutoIT experience (as well, it will be distributed as an .exe with no tray icon), so I need to make that it displays adequate feedback so that I can troubleshoot in the event that there is a failure. Thanks in advance. Link to comment Share on other sites More sharing options...
Valuater Posted October 30, 2006 Share Posted October 30, 2006 Maybe... _IEErrorHandlerRegister() see help 8) Link to comment Share on other sites More sharing options...
DuncanM Posted October 30, 2006 Author Share Posted October 30, 2006 Maybe..._IEErrorHandlerRegister()see help8)Thanks - maybe I'm missing something with _IEErrorHandlerRegister(), but I'm looking for something that's not so cryptic so that when the end user calls me, they will be able to read an error from (for example) a popup window. Basically, I just want to know where the script is stopping, and why. Will this require adding checks to be written for every WinWait, object creation, etc? Link to comment Share on other sites More sharing options...
Valuater Posted October 30, 2006 Share Posted October 30, 2006 (edited) Thanks - maybe I'm missing something with _IEErrorHandlerRegister(), but I'm looking for something that's not so cryptic so that when the end user calls me, they will be able to read an error from (for example) a popup window. Basically, I just want to know where the script is stopping, and why. Will this require adding checks to be written for every WinWait, object creation, etc? i understand you are working with "object references" the _IEErrorHandlerRegister ("MyErrFunc") below will handle the object error and a message box will display the errors encountered.. MsgBox(0,"COM Error", $ErrorOutput) in the script below #include <IE.au3> ; Register a customer error handler _IEErrorHandlerRegister ("MyErrFunc") ; Do something Exit Func MyErrFunc() ; Important: the error object variable MUST be named $oIEErrorHandler $ErrorScriptline = $oIEErrorHandler.scriptline $ErrorNumber = $oIEErrorHandler.number $ErrorNumberHex = Hex($oIEErrorHandler.number, 8) $ErrorDescription = StringStripWS($oIEErrorHandler.description, 2) $ErrorWinDescription = StringStripWS($oIEErrorHandler.WinDescription, 2) $ErrorSource = $oIEErrorHandler.Source $ErrorHelpFile = $oIEErrorHandler.HelpFile $ErrorHelpContext = $oIEErrorHandler.HelpContext $ErrorLastDllError = $oIEErrorHandler.LastDllError $ErrorOutput = "" $ErrorOutput &= "--> COM Error Encountered in " & @ScriptName & @CR $ErrorOutput &= "----> $ErrorScriptline = " & $ErrorScriptline & @CR $ErrorOutput &= "----> $ErrorNumberHex = " & $ErrorNumberHex & @CR $ErrorOutput &= "----> $ErrorNumber = " & $ErrorNumber & @CR $ErrorOutput &= "----> $ErrorWinDescription = " & $ErrorWinDescription & @CR $ErrorOutput &= "----> $ErrorDescription = " & $ErrorDescription & @CR $ErrorOutput &= "----> $ErrorSource = " & $ErrorSource & @CR $ErrorOutput &= "----> $ErrorHelpFile = " & $ErrorHelpFile & @CR $ErrorOutput &= "----> $ErrorHelpContext = " & $ErrorHelpContext & @CR $ErrorOutput &= "----> $ErrorLastDllError = " & $ErrorLastDllError MsgBox(0,"COM Error", $ErrorOutput) SetError(1) Return EndFunc ;==>MyErrFunc i think this will do what you are asking Will this require adding checks to be written for every WinWait, object creation, etc? No, it only needs registered once 8) Edited October 30, 2006 by Valuater Link to comment Share on other sites More sharing options...
DuncanM Posted October 30, 2006 Author Share Posted October 30, 2006 (edited) I will give it a try - thanks for all your help! Edited October 30, 2006 by DuncanM Link to comment Share on other sites More sharing options...
DuncanM Posted October 31, 2006 Author Share Posted October 31, 2006 Ok, I'm testing it, but I haven't been able to get the error popup to appear when it's waiting for a window that's not there. I figured it would come up after the timeout, but so far nothing - any ideas? Link to comment Share on other sites More sharing options...
DuncanM Posted October 31, 2006 Author Share Posted October 31, 2006 I have the following code thus far: #include <IE.au3> ; Register a customer error handler _IEErrorHandlerRegister ("MyErrFunc") ;WinWait should time out, since this window doesn't actually exist WinWait("sdlkfja", "sdfljk") Exit Func MyErrFunc() ; Important: the error object variable MUST be named $oIEErrorHandler $ErrorScriptline = $oIEErrorHandler.scriptline $ErrorNumber = $oIEErrorHandler.number $ErrorNumberHex = Hex($oIEErrorHandler.number, 8) $ErrorDescription = StringStripWS($oIEErrorHandler.description, 2) $ErrorWinDescription = StringStripWS($oIEErrorHandler.WinDescription, 2) $ErrorSource = $oIEErrorHandler.Source $ErrorHelpFile = $oIEErrorHandler.HelpFile $ErrorHelpContext = $oIEErrorHandler.HelpContext $ErrorLastDllError = $oIEErrorHandler.LastDllError $ErrorOutput = "" $ErrorOutput &= "--> COM Error Encountered in " & @ScriptName & @CR $ErrorOutput &= "----> $ErrorScriptline = " & $ErrorScriptline & @CR $ErrorOutput &= "----> $ErrorNumberHex = " & $ErrorNumberHex & @CR $ErrorOutput &= "----> $ErrorNumber = " & $ErrorNumber & @CR $ErrorOutput &= "----> $ErrorWinDescription = " & $ErrorWinDescription & @CR $ErrorOutput &= "----> $ErrorDescription = " & $ErrorDescription & @CR $ErrorOutput &= "----> $ErrorSource = " & $ErrorSource & @CR $ErrorOutput &= "----> $ErrorHelpFile = " & $ErrorHelpFile & @CR $ErrorOutput &= "----> $ErrorHelpContext = " & $ErrorHelpContext & @CR $ErrorOutput &= "----> $ErrorLastDllError = " & $ErrorLastDllError MsgBox(0,"COM Error", $ErrorOutput) SetError(1) Return EndFunc ;==>MyErrFunc Now what I want it to do is, when the WinWait statement times out (because the window doesn't exist), have the error message popup appear. However, it is not doing this. What am I missing? Link to comment Share on other sites More sharing options...
DuncanM Posted November 1, 2006 Author Share Posted November 1, 2006 Can someone point out what I'm doing wrong from my code? Link to comment Share on other sites More sharing options...
MHz Posted November 1, 2006 Share Posted November 1, 2006 WinWait does not error... This is a strange concern as we have gone from a COM error to an AutoIt error? Please look at this example to check for a window. If Not WinWait('Title', '', 10) Then MsgBox(0x40000, 'Title', 'Houston...We have a problem') EndIf Link to comment Share on other sites More sharing options...
DuncanM Posted November 1, 2006 Author Share Posted November 1, 2006 WinWait does not error... This is a strange concern as we have gone from a COM error to an AutoIt error? Please look at this example to check for a window. If Not WinWait('Title', '', 10) Then MsgBox(0x40000, 'Title', 'Houston...We have a problem') EndIfMHz, that is what I was asking initially - basically, do I have to write individual checks for (almost) each statement (i.e. IF, ELSE), or is there a way to write a "blanket" function? From what you're saying, I'm thinking it's going to be the former of the 2, since WinWait doesn't timeout - correct? Link to comment Share on other sites More sharing options...
MHz Posted November 1, 2006 Share Posted November 1, 2006 WinWait does timeout. Maybe confusing how I stated error as being the @error macro as WinWait uses the return value instead of failure which you can boolean with checking directly or using Not for failure. In example If Not WinWait('Title', '', 10) Then MsgBox(0x40000, 'Title', 'Houston...We have a problem') EndIf oÝ÷ Ù«¢+Ø)%]¥¹]¥Ð ÌäíQ¥Ñ±Ìäì°ÌäìÌäì°ÄÀ¤Q¡¸(%5Í ½à ÁàÐÀÀÀÀ°ÌäíQ¥Ñ±Ìäì°Ìäí!½ÕÍѽ¸¸¸¹]¥¥Ð°= å Ìäì¤)¹%( A return of 0 is false and anything else is true so we boolean the result. The Not keyword makes booleaning easy to understand and read then checking for 0 or anything non-zero. Link to comment Share on other sites More sharing options...
MHz Posted November 1, 2006 Share Posted November 1, 2006 do I have to write individual checks for (almost) each statement (i.e. IF, ELSE)Sorry, missed some of your query.For good responses to errors and avoiding debugging nightmare, yes indeed. Writing up to 50% more code does pay off. You just need to be able to type alot for the effect. Link to comment Share on other sites More sharing options...
DuncanM Posted November 1, 2006 Author Share Posted November 1, 2006 That is exactly what I was asking..I want as much info as possible in the event of an error or pause in the script, so I'll just have to go back and add the If, Else statements. Thanks again! Link to comment Share on other sites More sharing options...
DuncanM Posted November 1, 2006 Author Share Posted November 1, 2006 Sorry, forgot to ask - can I do the same type of If/Else statements for a ControlClick, object creation, etc (as in, if the click or object creation fails, it returns a 0, otherwise a 1)? Link to comment Share on other sites More sharing options...
MHz Posted November 1, 2006 Share Posted November 1, 2006 Com objects do rely on @error normally. So do check error, the help file will help to inform. @error is best to check at default if available for the inbuilt function. $oShell = ObjCreate("shell.application") If @error Then MsgBox(0x40000, 'Object', 'Failed') EndIf Link to comment Share on other sites More sharing options...
MHz Posted November 1, 2006 Share Posted November 1, 2006 If the previous does not satisfy with COM errors then look close at the ObjEvent function within the help file. ObjEvent ( "AutoIt.Error" [, "function name"])especially the example. Link to comment Share on other sites More sharing options...
DuncanM Posted November 1, 2006 Author Share Posted November 1, 2006 Com objects do rely on @error normally. So do check error, the help file will help to inform. @error is best to check at default if available for the inbuilt function. $oShell = ObjCreate("shell.application") If @error Then MsgBox(0x40000, 'Object', 'Failed') EndIfYou're a genious..thanks! 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