Jump to content

Reset AutoIt.Error handler to default


60aside
 Share

Recommended Posts

Hi,

Can someone tell me how I can reset the error handler back to the default autoit handler after running this piece of code?:-

Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
            Func MyErrFunc() 
            msgbox(0,"Error","An error occured processing the SQL query."&@lf&"Please retry.")
            exit
            Endfunc
            $conn.Open($DSN)
                        #cs
                        reset error back to default handler after this point?
                        #ce

thanks

Link to comment
Share on other sites

answer - with this :)

Global $oMyError = ""
Eehhh... let's think about this a moment.

There is no default handler. So, in removing the handler you do return to the default, in a manner of speaking.

But there might have already been another COM error handler declared besides the default (none). If you mean to return to that, it would look more like this:

Global $sMyErrorSav = ObjEvent("AutoIt.Error") ; Save the old handler

Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Set the new handler

; Stuff happens

Global $oMyError = ObjEvent("AutoIt.Error",$sMyErrorSav) ; Restore the old handler

A problem arises from that code: The handler has to know what variable was used to save the COM event object, so it can do things like:

MsgBox(16, "COM Error", "Error number was: " & $oMyErrFunc.Number)

If the old variable was actually $oMySupperCoolErrorHandler then $oMyErrFunc.Number won't work. You can find out what the old COM error function name was, but there is no way to find out what the old variable name was, unless you declared it.

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...