Scale to “raise” no arguments in handled exception handlers in Python 2 and 3

Consider the following minimal example:

try: raise Exception('foo') except Exception: try: raise Exception('bar') except Exception: pass raise 

Running this code with Python 2 raises an exception panel, running it with Python 3 raises an exception foo. However, the documentation for Python 2 and Python 3 claims that raise without expression will raise "the last exception that was active in the current scope." Why is the difference in Python 2 and 3? Is the difference documented anywhere?

+6
source share
1 answer

Areas vary because Python 3 is more advanced. :)

The scope for bar begins with indentation of try and ends after the last sentence in its except clause (or in the finally section there was one); naked raise clearly in the stanza of foo except , and this is what is being rereformed.

This is one of those little things that were fixed in Python 3. Documents can be sharper.

+2
source

Source: https://habr.com/ru/post/982949/


All Articles