Results 1 to 16 of 16

Thread: What's the equivalent of VB On Error Resume Next in C#?

  1. #1

    Thread Starter
    Hyperactive Member vincentg's Avatar
    Join Date
    Jun 2005
    Location
    Chicago IL, USA
    Posts
    261

    What's the equivalent of VB On Error Resume Next in C#?

    What's the equivalent of VB On Error Resume Next in C#?

    Thanks..

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: What's the equivalent of VB On Error Resume Next in C#?

    There isn't one, thankfully.
    I don't live here any more.

  3. #3
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: What's the equivalent of VB On Error Resume Next in C#?

    You have to try and Catch statements.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,173

    Re: What's the equivalent of VB On Error Resume Next in C#?

    Ah, the bane of Visual Basic programming. I hope not to see it soon.

  5. #5
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479

    Re: What's the equivalent of VB On Error Resume Next in C#?

    Quote Originally Posted by vincentg
    What's the equivalent of VB On Error Resume Next in C#?
    Good coding!

  6. #6
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: What's the equivalent of VB On Error Resume Next in C#?

    No, good code is the opposite of resume next
    I don't live here any more.

  7. #7
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479

    Re: What's the equivalent of VB On Error Resume Next in C#?

    Quote Originally Posted by wossname
    No, good code is the opposite of resume next
    Sorry my mistake.

  8. #8
    Lively Member deranged's Avatar
    Join Date
    Jun 2004
    Location
    TN
    Posts
    104

    Re: What's the equivalent of VB On Error Resume Next in C#?

    an example would be:
    Code:
    try
    {
    //THIS CODE WILL ATTEMPT TO EXECUTE
    
    //Put in anything that you think might cause an error
    
    }
    catch(Exception e)
    {
    //THIS IS WHAT HAPPENS IF THAT CODE CAUSES AN ERROR
    
    //It's probably the best idea to put in code that will alert the user that an error has occurred.
    
    }
    Last edited by deranged; Oct 6th, 2005 at 02:48 PM.

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: What's the equivalent of VB On Error Resume Next in C#?

    Even so you should only use Try/Catch as a last resort. And resist the temptation to wrap huge blocks of code in them. Only use it where exception handling is the only way to deal with all possible outcomes.

  10. #10
    Lively Member deranged's Avatar
    Join Date
    Jun 2004
    Location
    TN
    Posts
    104

    Re: What's the equivalent of VB On Error Resume Next in C#?

    Quote Originally Posted by penagate
    Even so you should only use Try/Catch as a last resort. And resist the temptation to wrap huge blocks of code in them. Only use it where exception handling is the only way to deal with all possible outcomes.
    True, but it works great for a time that you had some user input, and you want to convert a long to an integer for example. Sometimes it'll work, sometimes it wont.

  11. #11
    New Member
    Join Date
    Dec 2015
    Posts
    3

    Re: What's the equivalent of VB On Error Resume Next in C#?

    0

    down vote


    "On Error Resume Next" allows for "Inline Error Handling", which is the expert level error handling in VB. The concept is to handle errors line by line, either performing an action based on the error or ignoring the error when beneficial - but running code in the sequence in which it is written and not using code jumps.

    Unfortunately, many novices used "On Error Resume Next" to hide either their lack of ability or out of laziness from those using their applications by ignoring all errors. Try/catch is block level error handling, which in the pre-.NET world was intermediate by design and implementation.

    The problem with "On Error Resume Next" in VB.NET is that it loads the err object on every line of executing code and is, therefore, slower than try/catch. I'm somewhat alarmed that this forum checked and promoted an inane answer that claimed using On Error Resume Next is a bad habit and code litter. This is a VB forum; should it really be used for C# programmers to take shots at another language that they aren't well versed in? I favor C# because of it's elegant structure, which makes the horrific code that most code monkeys coming over to Microsoft from the SUN world and using C#, look exceptional. You see, this is the Microsoft world and criticizing another language in our toolset that you have no knowledge of; well, that's just so SUN like (you see VB slayed Java in the business development world back in the 90's; much like the combination of VB, C# and all of .NET is doing now). Don't trust the Tiobe index; they count students that have never developed a system in their lives and all universities use Java as their core teaching language because it's free.

    https://msdn.microsoft.com/en-us/lib...(v=vs.60).aspx

  12. #12
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: What's the equivalent of VB On Error Resume Next in C#?

    Wow - first post and you go to the morgue and dig up a thread from a prior decade!

    Welcome to the forum - I think ...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  13. #13
    New Member
    Join Date
    Dec 2015
    Posts
    3

    Re: What's the equivalent of VB On Error Resume Next in C#?

    I dug this up and so did you. This thread is not in the morgue; it's still out there misinforming people. So is this one:

    http://stackoverflow.com/questions/4...ume-next-for-c

    I'm certain you'll find my answer easily as it's in 2015.

    I think that all forums that should expire or are in the morgue as you claim, should be taken offline. Although most C# developers have stopped with their inane comments about VB due to most Gurus declaring VB the better language, slanderous threads about my beloved VB still exist out there. Although I adopted C# as my primary language long ago, VB is still King for RAD Win32 application development.

    Thank you for the semi snide welcome though.

  14. #14
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: What's the equivalent of VB On Error Resume Next in C#?

    Quote Originally Posted by Scott Net View Post
    I dug this up and so did you. This thread is not in the morgue; it's still out there misinforming people. So is this one:

    http://stackoverflow.com/questions/4...ume-next-for-c
    Firstly (and take this as tongue in cheek) -- once something is dug up, you can't dig it up a second time until it is buried again. szlamany didn't dig anything up, as it was already dug up by you.

    Secondly, (and maybe this is just because I don't care if people insult a language I use), what in these 2 threads are so grossly misinformed? 95% of the comments in both threads are simply stating that you should attempt to handle everything as gracefully as you can before blanketing something with a statement like "on error resume next" -- something that can, and will cause problems down the road if you don't know what you're doing. It would be like wrapping entire statements with a general try/catch because you don't want to deal with it.

    Quote Originally Posted by Scott Net View Post
    Although most C# developers have stopped with their inane comments about VB due to most Gurus declaring VB the better language, slanderous threads about my beloved VB still exist out there. Although I adopted C# as my primary language long ago, VB is still King for RAD Win32 application development.
    Can you post something proving this point? It seems counter intuitive for someone to claim VB is the be-all-end-all and then goes on to say they ditched it for C#. I know a lot of former VB6 and VB.NET programmers (many of which come to this site) who claim the complete opposite. You can argue that VB is still great at RAD (and many do successfully), but claiming that it is "King" and "most Gurus declaring VB the better language" seems quite bold and something that would definitely benefit being backed up with some actual citations.

  15. #15
    New Member
    Join Date
    Dec 2015
    Posts
    3

    Re: What's the equivalent of VB On Error Resume Next in C#?

    The thread was never actually buried as it's still online and not closed; so you're dug statement is bizarre and humorless; I'll just chalk it up as weird. It's also a little strange that you're responding for someone else, szlamany should have responded but you did for some odd reason. You're no where else on this thread; I wonder how you knew it was active again.

    Also, I do care if people misinform others due to their ignorance of a coding concept and and how it should be used and turn a question into an ignorance thread. Apparently, you also know nothing of the correct implementation of inline error handling and that it was taught in Microsoft VB Trainings in the 90's for VB as the expert level for error handling. I'm certain you've never done any C programming or you would understand inline error handling. I stated my case clearly. You may want to take another look at the other blog in which I gave an excellent example of how On Error Resume Next should be used. Read it a little more closely and try to comprehend it, rather than misrepresenting my posts and words. In that blog, I also give a nice C# coding alternative for handling situations in which one would need to check each line of code for error conditions in order to keep moving in sequence.

    I never said I ditched VB; you made that one up. I did say that I favor C# because of its elegant structure. This shows a serious lack of comprehension on your part; so, I'm not at all surprised by the fact that you can't comprehend the rest of what I've written correctly and can't grasp inline error handling.

    I never said VB was the be-all-end-all as you claim; just more RAD. Your world of pretend is representative of this thread. There isn't too much one can say, when someone is going to pretend they said something else.

    Also counterintuitive is one word; your grasp of the English language might be representative of your grasp of any type of coding language.

    Here's a few links; any expert in both languages knows that VB is more RAD. My complaint with VB is that it allows imbeciles to write horrific code due to implicit conversion. C#s strong typing stops this. Of course, VB shops can force the use of Option Strict and, unfortunately, C# is allowing dynamic typing now and it's open season for runtime errors in C# development now.
    https://www.simple-talk.com/dotnet/....better-than-c/
    http://www.wiseowl.co.uk/blog/s176/v...ic-c-sharp.htm
    http://www.vbrad.com/article.aspx?id=65

  16. #16
    Administrator Steve R Jones's Avatar
    Join Date
    Apr 2012
    Location
    Largo, FL.
    Posts
    1,820

    Re: What's the equivalent of VB On Error Resume Next in C#?

    And we'll go ahead and close slash end this discussion.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width