Re: [Python-ideas] Block-Scoped Exception Handlers

It looks frankly a bit like an "on error goto errorhandler" statement but with a few drawbacks to that. How can you indicate the 'exception handled block' should end, when there's no indentation level involved? It would force the exception block to service all code until the end of that indentation level but what happens on within the indentation level is defined by other more functional criteria. The proposed construct could not replace the normal try/catch syntax because of that, but it can also not mix with the normal syntax well because it's too similar to it and hence confusing. The gain of the proposed construct seems to be to save 1 indentation level. Even when this would be worth the cost it would be more logical to still put the except block at the end of the functional block. So instead of the proposed: def process_todo(todo): except Exception, e: raise OverallTodoError("Not expected") from e with Timer("todo processing"): # pre-processing for t in todo: except Exception, e: raise TodoError("oh dear!") from e # do error p the below is more logical, since the main code remains the focus and the exception the afterthought: def process_todo(todo): with Timer("todo processing"): # pre-processing for t in todo: except Exception, e: raise TodoError("oh dear!") from e # do error p except Exception, e: raise OverallTodoError("Not expected") from e But this all leaves something implicit rather then implicit: the start (or in the proposal: the end) of the exception block. Robert

Oh dear! It appears I screwed up the indentation. Since I never see the emails I send to this list, I have no idea what you all were looking at. Maybe I should have used underscores for email: def process_todo(todo): ____except Exception, e: ________raise OverallTodoError("Not expected") from e ____with Timer("todo processing"): ________# pre-processing ________for t in todo: ____________except Exception, e: ________________raise TodoError("oh dear!") from e ____________# do error prone stuff ________# post-processing The exception handling code should be indented, but the code it applies to is not. On 5/4/2016 6:45 PM, Robert van Geel wrote:

To mitigate my indentation disaster, I posted the document on Github. https://github.com/klahnakoski/Block-Scoped-Exception-Handlers On 5/4/2016 6:45 PM, Robert van Geel wrote:

Oh dear! It appears I screwed up the indentation. Since I never see the emails I send to this list, I have no idea what you all were looking at. Maybe I should have used underscores for email: def process_todo(todo): ____except Exception, e: ________raise OverallTodoError("Not expected") from e ____with Timer("todo processing"): ________# pre-processing ________for t in todo: ____________except Exception, e: ________________raise TodoError("oh dear!") from e ____________# do error prone stuff ________# post-processing The exception handling code should be indented, but the code it applies to is not. On 5/4/2016 6:45 PM, Robert van Geel wrote:

To mitigate my indentation disaster, I posted the document on Github. https://github.com/klahnakoski/Block-Scoped-Exception-Handlers On 5/4/2016 6:45 PM, Robert van Geel wrote:
participants (2)
-
Kyle Lahnakoski
-
Robert van Geel