Function Reference

_IEErrorHandlerRegister

Register and enable a user COM error handler

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

 

Parameters

$s_functionName 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 then 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 customer 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.

 

Related

_IEErrorHandlerDeRegister

 

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
    $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