|
-
Jul 7th, 2005, 11:08 AM
#1
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.
-
Jul 21st, 2005, 08:53 AM
#2
New Member
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.
-
Aug 5th, 2005, 05:57 AM
#3
Frenzied Member
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
-
Aug 5th, 2005, 07:27 AM
#4
Re: Why doesn't my onError work?
 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
-
Aug 5th, 2005, 07:56 AM
#5
Frenzied Member
Re: Why doesn't my onError work?
 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
-
Aug 9th, 2005, 03:20 AM
#6
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.
-
Aug 9th, 2005, 08:43 AM
#7
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|