A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2012-January/115732.html below:

[Python-Dev] exception chaining

[Python-Dev] exception chaining [Python-Dev] exception chainingEthan Furman ethan at stoneleaf.us
Fri Jan 20 18:09:57 CET 2012
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~
More information about the Python-Dev mailing list

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