0

I'm working on a project and all of the catch statements are catching "Exception ex". Is this acceptable? (e.g. 1000's of Exception ex and no sub classes of Exception anywhere)

I'm aware this depends on the situation but I'm trying to get more of a grasp on it, from my perspective you could be missing things that happen when doing this and potentially make it harder to track down issues later?

AndroidGuy
  • 52
  • 7
symon
  • 670
  • 1
  • 7
  • 20
  • it really is very subjective but as a whole Exception ex covers any issue, if it doesnt matter specifically why something failed its not a bad thing, but the error you can show your users is usually "Error there was an error" rather than maybe do something specific maybe to rectify the error and try again – BugFinder Apr 11 '17 at 07:39
  • Providing a stack with the line number is provided you will be able to debug and find the problem. If you were to show the end user a problem, custom Exceptions could be better used. But it is rather subjective. –  Apr 11 '17 at 07:40
  • 1
    I think catching the general class exception is always a bad idea... unless you know what specific exception you are catching... and know how to deal with it. I would direct you to here: http://stackoverflow.com/questions/21938/is-it-really-that-bad-to-catch-a-general-exception – Faheem Apr 11 '17 at 07:40
  • http://stackoverflow.com/questions/426346/is-this-a-bad-practice-to-catch-a-non-specific-exception-such-as-system-exceptio ... http://stackoverflow.com/questions/6536149/is-it-always-a-bad-pratice-to-catch-system-exception ... http://softwareengineering.stackexchange.com/questions/164256/is-catching-general-exceptions-really-a-bad-thing – Tim Schmelter Apr 11 '17 at 07:42
  • Also related, my answer to [Why is “except: pass” a bad programming practice?](http://stackoverflow.com/questions/21553327/why-is-except-pass-a-bad-programming-practice/21553825#21553825) – The question is about Python but the general sentiment applies in the same way. – poke Apr 11 '17 at 07:42
  • 1
    If you think `Exception ex` is good code, why not declare every method to only take `object` parameters and return `object`s? – Damien_The_Unbeliever Apr 11 '17 at 07:43

0 Answers0