Jump to content

Ado Error Not Catched


Recommended Posts

Hello,

I am adding records to a table in an access database :

$objconn.execute( $strsql)

if @error=-1 then continueloop

Data are coming from a .csv file so I cannot predict what is in it.

Sometimes I may have duplicate keys.

In that case the error for duplicate key is not catched and I do not know how to handle this....

Thanks in advance for your help,

AL

Link to comment
Share on other sites

Not sure if this is what you need, but when working with COM objects, you must define an error handler. In the BETA help file, go to Contents --> Function Reference --> Obj/COM Reference, and scroll down to the section named "COM Error Handling" and see the sample code:

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler 

; Performing a deliberate failure here (object does not exist)
$oIE = ObjCreate("InternetExplorer.Application")
$oIE.visible = 1
$oIE.bogus 
if @error then Msgbox(0,"","the previous line got an error.")

Exit 


; This is my custom error handler 
Func MyErrFunc() 
   $HexNumber=hex($oMyError.number,8) 
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Windescription is: " & $oMyError.windescription ) 

   SetError(1); something to check for when this function returns 
Endfunc

This will prevent the script from crashing and exiting when it encounters a COM error. Took someone else pointing it out to me here, so just returning the favor.

J

Link to comment
Share on other sites

Not sure if this is what you need, but when working with COM objects, you must define an error handler. In the BETA help file, go to Contents --> Function Reference --> Obj/COM Reference, and scroll down to the section named "COM Error Handling" and see the sample code:

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler 

; Performing a deliberate failure here (object does not exist)
$oIE = ObjCreate("InternetExplorer.Application")
$oIE.visible = 1
$oIE.bogus 
if @error then Msgbox(0,"","the previous line got an error.")

Exit 
; This is my custom error handler 
Func MyErrFunc() 
   $HexNumber=hex($oMyError.number,8) 
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Windescription is: " & $oMyError.windescription ) 

   SetError(1); something to check for when this function returns 
Endfunc

This will prevent the script from crashing and exiting when it encounters a COM error. Took someone else pointing it out to me here, so just returning the favor.

J

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