Jump to content

Capturing the error without halting script


Go to solution Solved by JLogan3o13,

Recommended Posts

Posted

I'm trying to do connection to a SQL db and I have it working:

$sqlCon = ObjCreate("ADODB.Connection")
$sqlCon.Open($connectionString)
If @error Then
    $CheckForLocal=MsgBox(4, "ERROR", "Failed to connect to the database")
    If $CheckForLocal='7' Then
        $trackLocal='Y'
    Else
        Exit
    EndIf
EndIf

When i force the connection to fail (put in an invalid password) I expected that it would pop up the error, but it actually halts my script and gives this on the console output:

  Quote

 

"Y:__SQLTransacts.au3" (13) : ==> The requested action with this object has failed.:

$sqlCon.Open($connectionstring)

$sqlCon^ ERROR

 

Any idea on what I'm doing wrong?

Posted

Which version of AutoIt do you run?

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Your script should run fine with the latest stable.

The way COM errors are handled has been changed in the latest beta.

My UDFs and Tutorials:

  Reveal hidden contents

 

  • Moderators
  • Solution
Posted

For the latest beta, try capturing the error yourself. Something like this:

Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

$sqlCon = ObjCreate("ADODB.Connection")
$sqlCon.Open($connectionString)


Func _ErrFunc()
    $CheckForLocal=MsgBox(4, "ERROR", "Failed to connect to the database")
        If $CheckForLocal='7' Then
            $trackLocal='Y'
        Else
            Exit
        EndIf
EndFunc

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted
  On 12/16/2014 at 1:55 PM, water said:

The way COM errors are handled has been changed in the latest beta.

 

Where I can find any descriptions for this change ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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
  • Recently Browsing   0 members

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