Jump to content

Error Handling using IE.au3


 Share

Recommended Posts

I have created some scripts using IE.au3 but i havent implemented any good error handling logic yet. In case of any errors IE.au3 prints the errors in the console. I believe those errors are printed to console using __IEErrorNotify function. I want to use these error messages and insert those into a text file or an excel. Any ideas? Basically if error messages are generated from IE.au3 after accessing its functions, then i want to write them to a file.

Link to comment
Share on other sites

Hi,

I think you want _IEErrorHandlerRegister.

#include <IE.au3>
 
 
_IEErrorHandlerRegister("_IEErrorHandler") ; register custom IE error handler
 
; lets see it in action
$oIE = _IECreate("http://example.com", 0, 0) ; create (hidden) IE object
ConsoleWrite("URL: " & $oIE.document.URL & @CRLF) ; print URL to console
ConsoleWrite("Nothing: " & $oIE.triggerErrorHere & @CRLF) ; trigger error by invoking non existing attribute
 
 
; custom IE error handler function
Func _IEErrorHandler()
    Local $sError = "!> IE COM Error" & @CRLF
    $sError &= "-> ErrorScriptline   = " & $oIEErrorHandler.scriptline & @CRLF
    $sError &= "-> ErrorNumberHex     = " & Hex($oIEErrorHandler.number, 8) & @CRLF
    $sError &= "-> ErrorNumber       = " & $oIEErrorHandler.number & @CRLF
    $sError &= "-> ErrorWinDescription = " & StringStripWS($oIEErrorHandler.WinDescription, 2) & @CRLF
    $sError &= "-> ErrorDescription = " & StringStripWS($oIEErrorHandler.description, 2) & @CRLF
    $sError &= "-> ErrorSource       = " & $oIEErrorHandler.Source & @CRLF
    $sError &= "-> ErrorHelpFile       = " & $oIEErrorHandler.HelpFile & @CRLF
    $sError &= "-> ErrorHelpContext = " & $oIEErrorHandler.HelpContext & @CRLF
    $sError &= "-> ErrorLastDllError   = " & $oIEErrorHandler.LastDllError & @CRLF
    ConsoleWriteError($sError & @CRLF) ; do what you want with the error message
EndFunc   ;==>_IEErrorHandler
Edited by Robjong
Link to comment
Share on other sites

Yu can use _IEErrorHandlerRegister() withou wriing your own error handler and it will put the messages into global variables for you. Please read the helpfile for _IEErrorHandlerRegister().

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Thank You for the reply!

@Dale - How do i use these global variables? I read the help file but couldnt figure out how to use it. Can you please refer my sample script below and show me how to use it.

@RobJong - I tried using the custom error handler but i am not sure why it doesnt seem to work. I read the help file for _IEErrorHandlerRegister but couldnt get this working. Please see the sample code below. I have given a wrong name attribute value for password. I do get the default message from IE.au3 like below but the custom error handler ( _IEErrorHandler()) in the script below is not called and it doesnt show below error message. I need some way to control these messages so that i can write it to a log file.

Error Message --

"--> IE.au3 V2.4-0 Error from function _IEFormElementGetObjByName, $_IEStatus_InvalidObjectType

--> IE.au3 V2.4-0 Error from function _IEFormElementSetValue, $_IEStatus_InvalidDataType"

------

My Sample Script

#include <IE.au3>

_IEErrorHandlerRegister("_IEErrorHandler") ; register custom IE error handler

$oIE = _IEAttach("Dev Con - Internet Explorer", "Title")

$oDomain = _IEGetObjByName($oIE, "domain")

_IEFormElementSetValue($oDomain, "UNTOPR")

$oPwd = _IEGetObjByName($oIE, "password111") ; purposefully inserted a wrong name attribute value. So this line will throw error in the console.

_IEFormElementSetValue($oPwd, "TEst")

Func _IEErrorHandler()

ConsoleWriteError("I am in error handler function" & @CRLF)

Local $sError = "!> IE COM Error" & @CRLF

$sError &= "-> ErrorScriptline = " & $oIEErrorHandler.scriptline & @CRLF

$sError &= "-> ErrorNumberHex = " & Hex($oIEErrorHandler.number, 8) & @CRLF

$sError &= "-> ErrorNumber = " & $oIEErrorHandler.number & @CRLF

$sError &= "-> ErrorWinDescription = " & StringStripWS($oIEErrorHandler.WinDescription, 2) & @CRLF

$sError &= "-> ErrorDescription = " & StringStripWS($oIEErrorHandler.description, 2) & @CRLF

$sError &= "-> ErrorSource = " & $oIEErrorHandler.Source & @CRLF

$sError &= "-> ErrorHelpFile = " & $oIEErrorHandler.HelpFile & @CRLF

$sError &= "-> ErrorHelpContext = " & $oIEErrorHandler.HelpContext & @CRLF

$sError &= "-> ErrorLastDllError = " & $oIEErrorHandler.LastDllError & @CRLF

ConsoleWriteError("Error Message --> " & $sError & @CRLF) ; do what you want with the error message

EndFunc ;==>_IEErrorHandler

THank you everybody for your time and help!

Link to comment
Share on other sites

  • 5 years later...

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
 Share

×
×
  • Create New...