Important alert: (current site time 7/16/2013 1:02:21 AM EDT)
 

article

A Quick Way To Handle Errors

Email
Submitted on: 11/28/2000 4:07:30 PM
By: Chris Blaker  
Level: Beginner
User Rating: By 19 Users
Compatibility: VB 5.0, VB 6.0
Views: 24413
author picture
(About the author)
 
     This is for all the beginners out there that have problems with their apps making errors. I dont care about votes it's just to help you all out, you advanced guys know this but some of the beginners wont.

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				'Simple, just put the below code above 
any of your other codes, so if it has an error the program wont crash. 
On Error Resume Next
'It cant be more simple.


Other 7 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

11/28/2000 6:06:00 PMAndy Stagg

um.. dude, i think just about everyone knows that...
(If this comment was disrespectful, please report it.)

 
11/28/2000 8:51:27 PMAckbar

Well yes I did know that. And true I'm sure a number of other people do. But I know everyone doesn't. And I'm sure it can and will help someone. However if you add:

if err then msgbox "Error: " & err.number & chr(10) & err.description, vbokonly + vbcritical, "Error: " & err.number

at the bottom of the function it will also give a messagebox explaining the error to the user. That is just an example of course and could be modified to suit your needs. :)
(If this comment was disrespectful, please report it.)

 
11/28/2000 10:29:34 PMThomas Michael

If you are using in-line error handling, make sure you use Err.Clear and the end of your Error Handler or Else the Error object will still contain an error.
(If this comment was disrespectful, please report it.)

 
11/28/2000 11:26:27 PMAckbar

Hmm. I've never had that problem before, and never have cleared the error with err.clear. Interesting though, I will have to investigate further.
(If this comment was disrespectful, please report it.)

 
11/29/2000 1:53:11 AMChris Bradley

yes Andy, alot of people DO know that, but hence the beginners. It's for them if they dont know how to do it, simple.
(If this comment was disrespectful, please report it.)

 
11/29/2000 12:14:48 PMdonovan

didnt know about the err.clear either..see everyoen can get somthign fromit ...even if it isnt in just the submission btu the discussion..but so few discussions take place *sighs*
(If this comment was disrespectful, please report it.)

 
12/1/2000 8:05:26 PMthomas

Yes, inline error handling can be great. But the point about using Err.Clear cann
(If this comment was disrespectful, please report it.)

 
12/1/2000 8:06:29 PMthomas

Hmm. My last post was cut off after an excruciating registration process. Sorry all, but I give up (and it was good, too :))
(If this comment was disrespectful, please report it.)

 
12/1/2000 11:15:17 PMChris Bradley

lol, is'nt it always the way.
(If this comment was disrespectful, please report it.)

 
12/2/2000 9:05:13 PMWilliam

This may be useful for beginners, but it is should in no way, shape, or form be thought of as
(If this comment was disrespectful, please report it.)

 
12/3/2000 5:23:38 PMChris Bradley

I believe you got cut off there will.
I hope it was'nt something I was going to have to delete.
(If this comment was disrespectful, please report it.)

 
12/7/2000 6:52:47 AMHenry Collingridge

Avoid the crappy login system on this site - login as guest/guest
(If this comment was disrespectful, please report it.)

 
12/7/2000 6:54:14 AMHenry Collingridge

Before using this code, go to msdn.microsoft.com and do a search for
(If this comment was disrespectful, please report it.)

 
6/7/2001 10:24:22 AMWilliam M.

Sure.. this will handle errors, however, it is NOT the best way to do so. This introduces hard to find bugs in your application because the code continues to execute regardless of the errors. Your code should always look to handle the errors appropriately, while cleaning up after itself. This, too, is for beginners. DOn't want them to get into the BAD, BAD, BAD habit on On Error Resume Next
(If this comment was disrespectful, please report it.)

 
6/15/2002 7:41:52 AMAhmed Adel

i don't think this is the way to handle...like this errors will appear and won't be able to debug the system..besides the system could simply crash and you won't know the reason .... i think you should be used only in certain situations....
(If this comment was disrespectful, please report it.)

 
6/15/2002 7:43:49 AMAhmed Adel

sorry ..i mistyped it ... " like this , Error won't appear .. and it should be used in certain situations.."
(If this comment was disrespectful, please report it.)

 
6/15/2002 2:04:55 PMSurlina

This code have accessed 6482 times. WHY ?!?!?!?!?!

(If this comment was disrespectful, please report it.)

 
6/16/2002 4:25:08 AMNoksok

Well, I don't think skiping errors is the best way to correct them, that's just pushing the proplem back and in the end, still you have to deal with it somewhere. I like to use an Add-in to VB that adds/removes line numbers. And every time I compile my code I add the numbers and then again remove them, when I wan't to edit the code. That way I can get the procedure name of the error and also get the line number where the error accured with Erl.
(If this comment was disrespectful, please report it.)

 
6/17/2002 6:26:24 AMTom

No offense, but I can't believe this is code of the day. Bludgeoning your way through code ignoring all errors that may occur is bad practice and should be avoided by everyone (including beginners)
(If this comment was disrespectful, please report it.)

 
6/18/2002 3:16:45 AMKobie

Don't knock the author on this one. I am not a great VB programmer yet, still learning the ropes. Although I knew about it before coming here, I feel I need to leave a comment. Resume Next has proved very helpful, simply because my programs don't fall over! To have a program crash on you is not looked upon lightly here. I use it, along with a Select Case - Case Else (to trap any unexpected errors) to do my error trapping. It is a quick, easy to use Error handler, that works very well for beginners. I am sure, once I have advanced my knowledge of VB that it's usefullnes will end, but for now it's the easiest solution. Thanks for the submission. I wish more people would consider absolute beginners and not worry what the advanced users are going to say about their submission.
(If this comment was disrespectful, please report it.)

 
7/19/2002 5:12:32 PMError Debugging

Uhm.. guys.. there's a reason you're getting an error, whether it's list index out of bounds or something didn't work.. you need to write error handlers instead of just doing On Error Resume next. Obviously if something errored in a procedure or function then the rest of it could be scrap if an invalid value is returned or whatnot. Err.clear or whatever it is and moving on isn't the way to go. :P Look WHY it errored and fix it, don't work around it
(If this comment was disrespectful, please report it.)

 
4/18/2003 5:05:58 AM

Dear Sir
Please send to me many aplications for visual Basic,includes form and source code and best solution for a aplication
Thak you very much!
Best regards
Phat
(If this comment was disrespectful, please report it.)

 
4/9/2005 1:14:23 AM

ConnectTo "http://www.planetsourcecode.com"

Connection.Address = ?++.GoBack

//End of code
(If this comment was disrespectful, please report it.)

 
4/9/2005 1:16:19 AM

Me.Name = "questionPlusPlus"
//sorry
(If this comment was disrespectful, please report it.)

 
3/11/2006 3:34:41 PMuiu

uiu
(If this comment was disrespectful, please report it.)

 
5/23/2007 3:49:18 PMjude

tnx...yeah...it did better..any other ways????
(If this comment was disrespectful, please report it.)

 
5/2/2009 1:09:49 AMMafia

yes on error resume next is good but , its not a complete solution in coding...tell more?
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.