Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Error handling question

Posted on 2003-12-08
5
Medium Priority
?
297 Views
Last Modified: 2010-05-03
When running my code through several code analyzers, they all say that an error handling statement should be included in the sub or function where I didn't have an 'On Error...' statement.  I didn't think to put error handling in a sub/function where there's only 1 line, e.g. a variable assignment.

Is it advisable to put the 'On Error Resume Next' statement in routines that don't really need error handling?  It seems like there's a lot of code bloat if one does that.

Thanks.
0
Comment
Question by:halfondj
5 Comments
 
LVL 43

Assisted Solution

by:TimCottee
TimCottee earned 400 total points
ID: 9896173
Hi halfondj,

As with all things, it is a matter of judgement. Technically I suppose you could say that even a simple variable assignment may generate an error if for example you try to assign too large a value to an integer you will get an overflow error. The issue with this is that if you have error handling in a procedure which then calls another one without error handling, you will not be able to trap the real error because it will get consumed into the calling procedure's error handler.

A rule of thumb is that if anything could cause any error to be raised you need to handle it. There are some VB add-ins which allow you to add such error handling with a single keystroke combination and this is what I tend to use. I have  default error handling script and apply it to any new function or procedure. This way at least I can be sure that I have trapped any errors where they have occurred and not had them consumed by other error handling which can make debugging code quite difficult.

Tim Cottee MCSD, MCDBA, CPIM
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 
LVL 14

Assisted Solution

by:ajexpert
ajexpert earned 400 total points
ID: 9896189
Hi,
There is no need for declaring error handler in procedure which contains only declaration of variables.  But the general routine should be to add error handlers
These links should you
http://www.vbcity.com/forums/faq.asp?fid=6&cat=Error%20Handling
http://www.vb-helper.com/tut6.htm

0
 
LVL 5

Accepted Solution

by:
mccainz2 earned 400 total points
ID: 9896215
YES YES YES

Error handling in every sub,function etc.....
Much preferable than a runtime crash to desktop
:)

As far as On error resume next ,
I do use that , usually in functions or subs where I'm fairly positive errors wont cascade  as a result ....
 ... also a good idea to mix and match error_handling ...

function start

on error resume next
.....simple code
on error goto err_handler
.....Some ADO code
on error resume next
....more trivial code
err_exit:
exit func
err_handler:
 handle error

function end
0
 

Author Comment

by:halfondj
ID: 9896264
Thanks for all the answers.  I increased the points and split them evenly.
0
 

Author Comment

by:halfondj
ID: 9896265
Thanks for all the answers.  I increased the points and split them evenly.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question