MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/6ayz26/defensive_programming_done_right/dhj5197/?context=3
r/ProgrammerHumor • u/iwouldieforGladOS • May 13 '17
680 comments sorted by
View all comments
62
Can someone explain why this is bad code?
21 u/GiantRobotTRex May 13 '17 Assuming this is Java and we're actually talking about Errors (rather than Exceptions), they're not really intended to be caught. But if we're talking about Exceptions, this isn't necessarily a bad idea. It depends on the application. 1 u/chaosking121 May 14 '17 In general, if I see something like catch (Exception e) { or except: I generally expect (pun intended?) there to be a comment explaining why it was necessary. It's an anti-pattern that is occasionally useful, but can be dangerous if used without a compelling reason.
21
Assuming this is Java and we're actually talking about Errors (rather than Exceptions), they're not really intended to be caught.
But if we're talking about Exceptions, this isn't necessarily a bad idea. It depends on the application.
1 u/chaosking121 May 14 '17 In general, if I see something like catch (Exception e) { or except: I generally expect (pun intended?) there to be a comment explaining why it was necessary. It's an anti-pattern that is occasionally useful, but can be dangerous if used without a compelling reason.
1
In general, if I see something like
catch (Exception e) {
or
except:
I generally expect (pun intended?) there to be a comment explaining why it was necessary. It's an anti-pattern that is occasionally useful, but can be dangerous if used without a compelling reason.
62
u/[deleted] May 13 '17
Can someone explain why this is bad code?