0

it's not dublicate! U can see it! In my question second code has not variable.

Is this two code exactly same?

catch(Exception){
     Console.WriteLine("Something");
}

and:

catch
{
Console.WriteLine("Something");
}
Person.Junkie
  • 1,816
  • 4
  • 21
  • 31
  • 1
    Yes, they're both bad programming practice. They both ignore the exception. You should only catch exceptions that you can actually _handle_. Ignoring an exception is not handling it. You'll never know what went wrong, and most likely, your code will keep going until something goes visibly wrong, far away from where the problem started. Just get rid of most try/catch blocks. – John Saunders Sep 12 '14 at 16:50
  • 1
    @JohnSaunders The only reasonable use case that comes to mind is if your code throws an exception when trying to log another exception, at which point you may need to just give up and not even try to log the error, but still closing the program gracefully for the user. – Servy Sep 12 '14 at 16:55
  • @Servy is absolutely correct - but I'd prefer to tell a beginner "don't use try/catch" rather than risk the beginner thinking that _all_ of his code is so important that it can't be permitted to crash. It's only something like the case of logging where it's more important to give up and not crash and never find out what went wrong, than it would be to allow the crash and find out what's wrong. – John Saunders Sep 12 '14 at 19:03

0 Answers0