Summary: Exception Chaining is cool, unless you are writing libraries that want to transform from Exception X to Exception Y as the the previous exception context is unnecessary, potentially confusing, and cluttery (yup, just made that word up!). For all the gory details, see http://bugs.python.org/issue6210. I'm going to attempt a patch implementing MRAB's suggestion: try: some_op except ValueError: raise as OtherError() # `raise` keeps context, `raise as` does not The question I have at the moment is: should `raise as` be an error if no exception is currently being handled? Example: def smurfy(x): if x != 'magic flute': raise as WrongInstrument do_something_with_x If this is allowed then `smurfy` could be called from inside an `except` clause or outside it. I don't care for it for two reasons: - I don't like the way it looks - I can see it encouraging always using `raise as` instead of `raise` and losing the value of exception chaining. Other thoughts? ~Ethan~
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4