Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looking for advice on error handling 2

Status
Not open for further replies.

Grizz2

Programmer
Dec 4, 2001
52
0
0
US
Hi all,
I've just finished my first application and am looking for suggestions. While developing I didn't use any error handling because I wanted to have all bugs show up so they could be fixed. Now that I think(???) I have 99% percent of them fixed, I thought error statements should be added just in case something was missed. Here's my questions.

1. Should I just add 'On Error Resume Next'
or
2. On Error GoTo ErrMess
ErrMess:
MsgBox "Give info on error and what to do"
Resume Next
or
3.On Error Exit Sub
My main intent would be to keep errors from ending the program.
Thanks
Grizz2
 
1. Only use this when you want a shortcut solution when the next statement might error and you know why.
on error resume next
db.execute "Drop table tablename"
on error goto erro_handle

is good if the tablename might not exist.

2. is good

3. is generally confusing. Nothing will happen and the user will become bewildered, which is bad.
Peter Meachem
peter@accuflight.com
 
So putting an error statement at the top of every sub doesn't help anything? Error statements should be used on individual procedures??
Grizz2
 
The following coding sequence for insert, update and delete database operations using ADO will keep your users and support staff happy. You drop the connection to the table after "rollback" of data entries, thus preventing partial writes (cleanup after a faulty broadcast)

dim conx as adodb.connection
set conx = new adodb.connection

sub writeToTable
code
code
on error goto ERROREXIT
conx.beginTrans
SQL code to insert, delete or update a table
conx.commitTrans
set conx = nothing
exit sub

ERROREXIT:
conx.rollback
<write error info to Ops Log>
<send error message to screen>
<additional recovery code>
set conx = nothing

end sub
 
I think you need to think about your code a bit. Access puts error code in every sub given half a chance. This is ok, but not really required. If you do on error goto Error_Handle, the have some code, then call a sub with no error handle, the second sub errors will go back to the first sub error_handle. This may be convenient or not. VB error handling is a bit of a pain really. Peter Meachem
peter@accuflight.com
 
Ok, thanks. I don't have any database code in this project. Just many forms and reading-writing text files. I think most of the bugs are fixed and I guess was looking for a little insurance policy in an error statement.
Thanks again.
Grizz2
 
The answer given by RickSpr to a similar question in Thread222-52018 : On Error Statement is recommended reading for anyone dealing with the problem _________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
Thanks that was very informative.
Grizz2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top