Comment Re:try/except/else/finally (Score 1) 228
The point is to limit the scope of the try block and to only catch exceptions on code that you expect to throw things in. Here's an example:
try:
foo = someDict[key]
except KeyError:
return None
else:
return myCrazyFunction(foo)
If myCrazyFunction throws a KeyError you probably want it propagated upwards, not caught.
try:
foo = someDict[key]
except KeyError:
return None
else:
return myCrazyFunction(foo)
If myCrazyFunction throws a KeyError you probably want it propagated upwards, not caught.