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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you have too much Error handling?

Status
Not open for further replies.

SirPaladin

Programmer
Jul 9, 1999
32
0
0
US
I've recently tried to make a program of mine a bit more stable by adding a lot Error handling throughout the code. However, now I'm sometimes (not always) getting "Out of Memory" errors where I didn't before (with only a couple of other apps open). I'm not sure if these are being caused by having recently added error handling in most of my procedures, though I can't see why. I was under the impression that "On Error GoTo ErrorHandler" automatically disables itself and releases the memory once it leaves that procedure without needing an implicit "On Error Goto 0". Can you have too much Error handling? Of course, it's entirely possible the problem has nothing to do with my code, despite my computer having 128mb RAM.
 
I don't believe much err handling can raise 'out of memory' error. Like you, I put Error Handling in every vital procedure but it never spend too much memory.

Possibility, 'out of memory' problem is caused by any opened object which are not cleared from memory.

To reduce memory used by VB to handle error you can put Err.Clear statement before leaving the error handling.
 
If you have a large number of objects that are derived from classes, you could try: set myObject = nothing when you are finished using the object.

From what I have read, VB doesn't appear to have a very good garbage collection routine....

You might also post some snippets of your code. Another thing to try is run it on another computer...

Troy Williams B.Eng.
fenris@hotmail.com

 
Well, there might be various reasons why you might be getting an "Out of Memory error".

One reason maybe that one of your error handlers is being called recursively because of an even being fired. This reason seems more likely and you might want to use F8 to go through the statements in your code.

The memory hogging problem might also occur as you might have seen that was posted above. But this won't happen unless you have a lot of objects open and there are many users. Since you are still in development stage I do not think this might be an issue here.

Anyway, try this one out. It might help you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top