[Python-Dev] exception chaining (original) (raw)
Ethan Furman ethan at stoneleaf.us
Fri Jan 20 18:09:57 CET 2012
- Previous message: [Python-Dev] Summary of Python tracker Issues
- Next message: [Python-Dev] exception chaining
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 ofraise
and losing the value of exception chaining.
Other thoughts?
Ethan
- Previous message: [Python-Dev] Summary of Python tracker Issues
- Next message: [Python-Dev] exception chaining
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]