Function Reference


_IEErrorHandlerRegister

Register and enable a user COM error handler

#include <IE.au3>
_IEErrorHandlerRegister([$s_functionName = "__IEInternalErrorHandler"])

Parameters

$s_functionName [optional] String variable with the name of a user-defined COM error handler, defaults to the internal COM error handler in this UDF

Return Value

Success: Returns 1
Failure: Returns 0 and sets @ERROR
@Error: 0 ($_IEStatus_Success) = No Error
1 ($_IEStatus_GeneralError) = General Error
@Extended: Contains invalid parameter number

Remarks

Important: When using your own error handler, the Error Object variable used MUST be named $oIEErrorHandler (see example).

AutoIt has the ability to trap COM errors and pass them through a custom error handler using the ObjEvent function. There is a problem with this for UDF writers however because only a single COM error handler can be in use at a time. For the UDF to use a COM error handler it must first deregister the user error handler, install its own and then put the user handler back in place. Unfortunately, by default, the UDF has no way to access the handle of the user error handler.

Using this routine you can register your COM error handler in a way that IE.au3 can gracefully remove and reinstate it when it needs to. You may either point to your own custom error handler or you may use the one developed for IE.au3 (the default). Using the default IE.au3 error handler you will also get some nice diagnostic information written to the console and some global variables that contain information about the trapped errors.

If you instantiate your own COM error handler without using this routine IE.au3 will not be able to trap some COM errors and you may experience some abrupt script terminations as a result.

If you use the default error handler (__IEInternalErrorHandler), the following global variables are set for you to reference: $IEComErrorNumber, $IEComErrorNumberHex, $IEComErrorDescription, $IEComErrorScriptline, $IEComErrorWinDescription, $IEComErrorSource, $IEComErrorHelpFile, $IEComErrorHelpContext, $IEComErrorLastDllError, $IEComErrorComObj and $IEComErrorOutput

You may control the display of COM error messages to the console with _IEErrorNotify.

Related

_IEErrorHandlerDeRegister, _IEErrorNotify

Example


; *******************************************************
; Example 1 - Register and later deregister a custom and the default IE.au3 error handler
; *******************************************************

#include <IE.au3>

; Register a customer error handler
_IEErrorHandlerRegister("MyErrFunc")
; Do something
; Deregister the customer error handler
_IEErrorHandlerDeRegister()
; Do something else
; Register the default IE.au3 COM Error Handler
_IEErrorHandlerRegister()
; Do more work

Exit

Func MyErrFunc()
    ; Important: the error object variable MUST be named $oIEErrorHandler
    Local $ErrorScriptline = $oIEErrorHandler.scriptline
    Local $ErrorNumber = $oIEErrorHandler.number
    Local $ErrorNumberHex = Hex($oIEErrorHandler.number, 8)
    Local $ErrorDescription = StringStripWS($oIEErrorHandler.description, 2)
    Local $ErrorWinDescription = StringStripWS($oIEErrorHandler.WinDescription, 2)
    Local $ErrorSource = $oIEErrorHandler.Source
    Local $ErrorHelpFile = $oIEErrorHandler.HelpFile
    Local $ErrorHelpContext = $oIEErrorHandler.HelpContext
    Local $ErrorLastDllError = $oIEErrorHandler.LastDllError
    Local $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