Results 1 to 7 of 7

Thread: Why doesn't my onError work? (Resolved)

  1. #1

    Thread Starter
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Why doesn't my onError work? (Resolved)

    I'm writing a word plugin which connects to a back end database. I've got the following code:-

    Code:
    On Error GoTo connErr61
        mConn.Open "Provider=SLXNetwork.1;User ID =" & mUserID & ";password=" & mPassword & ";Data Source = " & mDB & ";Extended Properties=""SLX Server=" & mServer & ";ADDRESS=localhost;Type=ODBC;PORT=" & mPort & """"
        MsgBox "open succeeded"
        mConn.CursorLocation = adUseClient
    Exit Sub
    connErr61:
        MsgBox "open failed"
        If MsgBox("Database connection failed. Check configuration? (Cancel will exit)", vbOKCancel, "Connection Error") = vbOK Then
            configure
        Else
            Err.Raise 100, "Config.Connect", "Connection Failed"
        End If
    End Sub
    The idea is that if the connection fails I give the user the option to configure the connection (via the configure method) or not to bother. If the user doesn't bother then the app should raise an error which will be caught at the top level and exit gracefully.

    The trouble is that if I give it an invalid password I get a runtime error on the mConn.open line and the app bombs out immediately. Neither the "open succeeded" or "open failed" message appears and, more importantly, the code which lets the user reconfigure doesn't fire. As a result, once there's a bad password the user can't get into the app at all.

    Shouldn't my "onError GoTo connErr61" force execution in to the connErr61 block?
    Last edited by FunkyDexter; Aug 9th, 2005 at 08:48 AM.

  2. #2
    New Member
    Join Date
    Jul 2005
    Posts
    5

    Re: Why doesn't my onError work?

    Have you set the error trapping options in VB? Tools->options->General->error trap

    It could also be a good idea to use " On error resume next" allowing the call to complete, and then check the return value (if there is one) to if the call has succeded.

  3. #3
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253

    Re: Why doesn't my onError work?

    Can you post the complete sub, please.
    "As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality." - Albert Einstein

    It's turtles! And it's all the way down

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Why doesn't my onError work?

    Quote Originally Posted by HFMa
    Have you set the error trapping options in VB? Tools->options->General->error trap

    It could also be a good idea to use " On error resume next" allowing the call to complete, and then check the return value (if there is one) to if the call has succeded.
    If I hear one more person suggest "on error resume next" I'm going to beat them to a bloody pulp. That's the WORST thing you can do... EORN is not error handling but error ignoring.

    Funky - two things: 1) Right-click in your code, select the "Toggle" menu... what is your error setting? 1) Break on all errors; 2) Break in Class; 3) Break only on Unhandled Errors.
    Make sure it is set to #3 option.

    Second, what does happen? - nevermind, I see it now.... OK, then is this happening during design (ie, when you've gotthe code loaded & running the app) or only when running the compiled app (I've seen cases where it worked in one, and not the other.)

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253

    Re: Why doesn't my onError work?

    Quote Originally Posted by techgnome
    If I hear one more person suggest "on error resume next" I'm going to beat them to a bloody pulp. That's the WORST thing you can do... EORN is not error handling but error ignoring.

    Funky - two things: 1) Right-click in your code, select the "Toggle" menu... what is your error setting? 1) Break on all errors; 2) Break in Class; 3) Break only on Unhandled Errors.
    Make sure it is set to #3 option.

    Second, what does happen? - nevermind, I see it now.... OK, then is this happening during design (ie, when you've gotthe code loaded & running the app) or only when running the compiled app (I've seen cases where it worked in one, and not the other.)

    Tg
    I agree. It'd be nice to see the complete function, though.
    "As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality." - Albert Einstein

    It's turtles! And it's all the way down

  6. #6

    Thread Starter
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Why doesn't my onError work? <resolved>

    Hi Guys

    I hadn't had any answers on this after the initial silence and I've since got around the problem by making the user define which connection string to use as part of configuration. So I can't post the complete function because it's been rewriten and no longer exhibits the problem. Thanks for the offer though.

    I basically always use 'Break on unhandled' because. Occasionally I'll switch it to break on all as this can help find errors that my error handlers are 'hiding' but 'unhandled' is as close as possible to real world so provides the best test.

  7. #7
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253

    Re: Why doesn't my onError work?

    Mark this thread as resolved?
    "As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality." - Albert Einstein

    It's turtles! And it's all the way down

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width