?
Solved

Error handling question

Posted on 2003-12-08
5
Medium Priority
?
296 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

719 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