On Error Resume Next Considered Harmful
Contents |
"On Error Resume Next"? If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to on error resume next vba visit from the selection below. Results 1 to 3 of 3 Thread: Classic VB - What is on error resume next vb6 example wrong with using "On Error Resume Next"? Tweet Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded on error resume next vbscript Mode Jan 20th, 2007,04:48 PM #1 si_the_geek View Profile View Forum Posts Thread Starter Super Moderator Join Date Jul 2002 Location Bristol, UK Posts 38,318 Classic VB - What is wrong with using "On Error Resume Next"? If it is used properly, "On on error resume next rxjava Error Resume Next" is a valid method of dealing with errors - but it is a method that needs to be used appropriately for the situation. While using it means that you don't get any 'annoying' error messages that stop your program, it can easily cause much bigger problems than that, such as: If one error happens, then the code after that point is likely to have errors too (especially if the first error occurred while doing something like setting the value of a variable). The follow-up
On Error Goto Line
error(s) that occur may be simple and 'safe', such as getting the wrong result displayed on screen (but not knowing it is wrong)... or they could be much more serious, such as accidentally deleting an important file, because you had an error getting the name of the file that you wanted to delete. If you have made any coding mistakes (such as putting a text value into an Integer variable) then your code wont do what it is supposed to do, and you wont know why. Not only is the problem hidden from you, but so is the location of it. If you are running within VB, you would normally get the line highlighted - but with "On Error Resume Next" you wont. In fact, you wont even know that there was an error, all you will know is that you have made some kind of mistake somewhere in that routine. If you don’t know what the problem is, or where it is, how will you fix it?What will the users of your program think if it gives them the wrong results? ..or does something nasty by mistake? They wont be happy, and they certainly wont think that you are a great programmer! As you are reading this article, you probably think that errors are a bad thing, and so hiding them is a good idea. As you get more experience you find that this is not the case, and errors are actually a good thing - they tell you either that you have done something wrong (and why
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers
On Error Goto 0
or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x on error resume next example Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only on error resume next not working takes a minute: Sign up What is the best alternative “On Error Resume Next” for C#? up vote 12 down vote favorite 2 If I put empty catch blocks for my C# code, is it going to be an equivalent http://www.vbforums.com/showthread.php?448401-Classic-VB-What-is-wrong-with-using-quot-On-Error-Resume-Next-quot for VB.NET's "On Error Resume Next" statement. try { C# code; } catch(exception) { } The reason I am asking this is because I have to convert a VB.NET code to C#, and the old code has ~200 "On Error Resume Next" statements although I am using a proper try {} catch {} in my new code, but is there is a better alternative? c# vb.net error-handling vb.net-to-c# share|improve this question edited Oct 25 '12 at 16:11 Peter Mortensen 10.3k1369107 http://stackoverflow.com/questions/4825422/what-is-the-best-alternative-on-error-resume-next-for-c asked Jan 28 '11 at 6:15 Neel 67621026 12 The lack of an alternative to On Error Resume Next wasn't just an unintentional oversight... Why do you possibly need this? If you explain the motivation behind your thoughts of doing this, I'm sure that someone here could give you a better solution. –Cody Gray Jan 28 '11 at 6:17 @Cody Gray - updated the reason of asking. Thanks –Neel Jan 28 '11 at 6:31 2 @MarkJ: Because even if (s)he leaves the code as VB.NET, it's still a good idea to replace On Error Goto Next with more structured exception handling (or none at all). –Cody Gray Jan 29 '11 at 2:04 4 @Cody It is an improvement to replace the error handling, but you have to assess how long it will take (how much it will cost) and whether the code needs substantial modifications. If the code works & doesn't need changing, there may be better things to do with the time instead. –MarkJ Jan 29 '11 at 14:21 1 @MarkJ: Fair enough. I don't disagree with you, I was just providing what I felt was a convincing argument for the other side. This is one of those design decisions you have to make. Do I stick with sloppy code that happens to work, or do I take the time to improve it for long-term benefits. I was assuming the reason the c
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs https://msdn.microsoft.com/en-us/library/5hsw66as.aspx and reference Dev centers Samples Retired content We’re sorry. The content http://www.gossamer-threads.com/lists/python/python/808525 you requested has been removed. You’ll be auto redirected in 1 second. Visual Basic Language Reference Statements F-P Statements F-P Statements On Error Statement On Error Statement On Error Statement For Each...Next Statement For...Next Statement Function Statement Get Statement GoTo Statement If...Then...Else Statement Implements Statement Imports Statement (.NET on error Namespace and Type) Imports Statement (XML Namespace) Inherits Statement Interface Statement Mid Statement Module Statement Namespace Statement On Error Statement Operator Statement Option
Post #1 of 8 (12257 views) Permalink Is there a way to continue after an exception ? hello, I would like my program to continue on the next line after an uncaught exception, is that possible ? thanks Stef Mientki krister.svanlund at gmail Feb20,2010,3:59PM Post #2 of 8 (12172 views) Permalink Re: Is there a way to continue after an exception ? [In reply to] On Sun, Feb 21, 2010 at 12:52 AM, Stef Mientki