How to Tell VB & Ado to not stop on error?

How to Tell VB & Ado to not stop on error?

Post by Davi » Fri, 10 Nov 2000 04:00:00



Is there a way to tell ADO to NOT stop when an error occurs, but allow
me to check the error code collection to check the errors?  Eg. I do
not wish to use a ON ERROR RESUME NEXT in my code, but tell ADO to
continue when it has an error and allow me to check the error via.
code.

Thanks

 
 
 

How to Tell VB & Ado to not stop on error?

Post by Tom Gilme » Fri, 10 Nov 2000 04:00:00


Why don't you want to use on error resume next? It works.

On Error Resume Next    'Enable error checking
rs.Update
If cn.Errors.Count <> 0 then
    'Do something
    cn.Errors.Clear
End If
On Error GoTo 0            'Turn off error checking

You use the On Error statement in those places where an error is
likely.
Or, you can wait til VB7 to use Try...Catch!

 - Tom


Quote:> Is there a way to tell ADO to NOT stop when an error occurs, but
allow
> me to check the error code collection to check the errors?  Eg. I do
> not wish to use a ON ERROR RESUME NEXT in my code, but tell ADO to
> continue when it has an error and allow me to check the error via.
> code.

> Thanks


 
 
 

How to Tell VB & Ado to not stop on error?

Post by Jimmy Kavanag » Sat, 11 Nov 2000 04:00:00


either use
    On Error Resume Next
or
    On Error Goto MyErr_Handler

If you use On Error Resume Next then you should check if an error as
occcured as often as possible
e.g.

    Dim rs as ADODB.Recordset

    rs.Open xx,yy,zz,blag, blah

    if Err.Number <> 0 then
        msgbox "An Error occured opening the recordset " & Err.Number & " "
& Err.Description
    endif

    rs.movefirst

    if Err.Number <> 0 then
    endif

 
 
 

How to Tell VB & Ado to not stop on error?

Post by Roland Roo » Fri, 01 Dec 2000 04:00:00


Or:

On error Goto Handle
....ADO stuff

On error goto 0
Exit sub/func
Handle:
    msgbox Err.Description '<-------Handle error
   resume next
   exit sub/func
End sub/func


> Why don't you want to use on error resume next? It works.

> On Error Resume Next    'Enable error checking
> rs.Update
> If cn.Errors.Count <> 0 then
>     'Do something
>     cn.Errors.Clear
> End If
> On Error GoTo 0            'Turn off error checking

> You use the On Error statement in those places where an error is
> likely.
> Or, you can wait til VB7 to use Try...Catch!

>  - Tom



> > Is there a way to tell ADO to NOT stop when an error occurs, but
> allow
> > me to check the error code collection to check the errors?  Eg. I do
> > not wish to use a ON ERROR RESUME NEXT in my code, but tell ADO to
> > continue when it has an error and allow me to check the error via.
> > code.

> > Thanks

 
 
 

How to Tell VB & Ado to not stop on error?

Post by Tom Gilme » Fri, 01 Dec 2000 04:00:00


I prefer to enable error trapping *only* when I suspect an error is
possible. If the error occurs, handle it, clear the error and disable
error trapping. If an error occurs somewhere that I didn't anticipate,
the user will get a run time error message. I'll hear about it and
have to fix it.

By the way, I was wondering why you didn't clear the error in your
example.

  - Tom


Quote:> Or:

> On error Goto Handle
> ....ADO stuff

> On error goto 0
> Exit sub/func
> Handle:
>     msgbox Err.Description '<-------Handle error
>    resume next
>    exit sub/func
> End sub/func

 
 
 

How to Tell VB & Ado to not stop on error?

Post by Carl Prothma » Fri, 01 Dec 2000 04:00:00



Quote:> I prefer to enable error trapping *only* when I suspect an error is
> possible. If the error occurs, handle it, clear the error and disable
> error trapping. If an error occurs somewhere that I didn't anticipate,
> the user will get a run time error message. I'll hear about it and
> have to fix it.

Hmmm...  Rather than having the application crash in front of a user because
there was no error handler, I prefer to trap all errors and log them if
nessessary, then show a "friendly" critical error message to the user.  This
means that all top-level procedures have Event Handlers.

--

Thanks,
Carl Prothman
Microsoft Visual Basic MVP
http://www.able-consulting.com

Please reply in the newsgroup.  I am unable to respond to requests for
assistance via private e-mail.

 
 
 

How to Tell VB & Ado to not stop on error?

Post by Jimmy Kavanag » Sat, 02 Dec 2000 04:00:00


I Agree with Carl

All erroes whould be trapped even if its just to provide a more polite
message to the user that something has gone wrong tather that having the
weird message "Object x does not support method Y" etc.

It also allows you to gracefully exit the application by properly closing
resources in use such as open files or ado tables,
network connections, references to objects etc. etc. etc.



> > I prefer to enable error trapping *only* when I suspect an error is
> > possible. If the error occurs, handle it, clear the error and disable
> > error trapping. If an error occurs somewhere that I didn't anticipate,
> > the user will get a run time error message. I'll hear about it and
> > have to fix it.

> Hmmm...  Rather than having the application crash in front of a user
because
> there was no error handler, I prefer to trap all errors and log them if
> nessessary, then show a "friendly" critical error message to the user.
This
> means that all top-level procedures have Event Handlers.

> --

> Thanks,
> Carl Prothman
> Microsoft Visual Basic MVP
> http://www.able-consulting.com

> Please reply in the newsgroup.  I am unable to respond to requests for
> assistance via private e-mail.