Re: [Python-Dev] suggestion for try/except program flow

2009-03-28 Thread Michael Haggerty
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 This seems like an unusual pattern. Are you sure you can't use try

Re: [Python-Dev] suggestion for try/except program flow

2009-03-27 Thread Hrvoje Niksic
Mark Donald wrote: Thanks for the idea, but I believe it has a different outcome. You'd have to copy the generic handler into an except clause to get exactly the behaviour I'm looking for, which is worse than nesting the try blocks Then simply change Exception to BaseException. Since all excep

Re: [Python-Dev] suggestion for try/except program flow

2009-03-27 Thread Nick Coghlan
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 wit

Re: [Python-Dev] suggestion for try/except program flow

2009-03-27 Thread Hrvoje Niksic
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 Ex

[Python-Dev] suggestion for try/except program flow

2009-03-27 Thread Mark Donald
I frequently have this situation: try: try: raise Thing except Thing, e: # handle Thing exceptions raise except: # handle all exceptions, including Thing It would be much more readable if there were a way to recatch a named exception with the generic (catch-all