Aug 11 2008
Try…Catch For No Reason
I’ve seen this time and time again and I’m sure just about every developer out there has seem the same sort of thing:
try { //many lines of code catch (Exception ex) { throw new Exception("Something went wrong dude!"); }
This is probably the single most un-helpful piece of code a developer can write. All you are doing is making you life and future developers lives harder when it comes to debugging. The whole point of the try…catch block is for times when you know an exception may happen and it allows you to gracefully handle it without the whole system crashing to the ground.
So lets have a closer look at what’s wrong with this code: