____def process_todo(todo):
____
____
pre_process()
____
____
for t in todo:
____
________exc
ept Exception, e:
_
___
_
___
_
___
_
break
___
_
___
_
___
_
process(t)
___
_
___
_
post_process() As an alternative to
___
____def process_todo(todo):
____
____
pre_process()
____
____
for t in todo:
____________try
_____
___
_
___
____
_
process(t)
___
________exc
ept Exception, e:
_
___
_
___
_
___
_
break
___
_
___
_
post_process()
___
Of course, a couple `try` nested statements make the indentation worse. For example, we wish to ignore problems in dealing with todo items, like above, but the todo items are complicated; each is a dict() of details. Failure to deal with one of the details is ignored, but the rest of the details are still attempted:
def process_todo(todo): ____pre_process() ____for t in todo: ________except Exception, e: ____________break ________for u, v in t.items(): ____________except Exception, e: ________________continue ____________process() ____post_process() Which is better than what I do now: def process_todo(todo): ____pre_process() ____for t in todo: ________try: ____________for u, v in t.items(): ________________try: ____________________process() ________________except Exception, e: ____________________continue ________except Exception, e: ____________break ____post_process()
At a high level: The `try/except/finally` is powerful structure. Realizing that the `try/finally` pair is very common leads to the creation of `with`. I am proposing the same logic for `try/catch` pair: They are commonly paired together and should have an optimized syntax.