Re: [Python-Dev] suggestion for try/except program flow
Mark Donald wrote:
I frequently have this situation:
try: try: raise Thing except Thing, e: # handle Thing exceptions raise except: # handle all exceptions, including Thing
How about: try: ... code that can raise Thing or another exception ... except Exception, e: if isinstance(e, Thing): # handle thing # generic exception handling
Hrvoje Niksic wrote:
How about:
try: ... code that can raise Thing or another exception ... except Exception, e: if isinstance(e, Thing): # handle thing # generic exception handling
That is indeed the idiomatic way of handling the original poster's use case without nesting a second try block. Any proposals for new dedicated syntax should probably go to python-ideas rather than here though. (It's a rare enough use case that I don't like the original poster's chances of getting much support for changes though) Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia ---------------------------------------------------------------
participants (2)
-
Hrvoje Niksic
-
Nick Coghlan