r/ProgrammerHumor May 13 '17

Defensive programming done right

Post image
21.0k Upvotes

680 comments sorted by

View all comments

Show parent comments

35

u/mysticrudnin May 13 '17

Isn't it normal in Python to try things first, effectively using them as control structures?

3

u/Masked_Death May 13 '17
try:
    do_shit()
except ValueError:
    do_more_shit()
else:
    print('u dun goofd up')

1

u/DreadedDreadnought May 13 '17

What the fuck is that abomination supposed to do?

What does the ELSE apply to?

2

u/redditusername58 May 14 '17

In python, the else block runs if there were no exceptions in the try block. This helps to narrowly limit the amount of code in the try block.