How is this different from the existing exception handling?

From  https://docs.python.org/3/tutorial/errors.html#exceptions :
 
> The last except clause may omit the exception name(s), to serve as a wildcard. Use this with extreme caution, since it is easy to mask a real programming error in this way! It can also be used to print an error message and then re-raise the exception (allowing a caller to handle the exception as well):

```python
import sys

try:
    f = open('myfile.txt')
    s = f.readline()
    i = int(s.strip())
except OSError as err:
    print("OS error: {0}".format(err))
except ValueError:
    print("Could not convert data to an integer.")
except:
    print("Unexpected error:", sys.exc_info()[0])
    raise
```

https://docs.python.org/3/library/exceptions.html

 https://docs.python.org/3/c-api/exceptions.html

On Sun, Oct 11, 2020, 12:25 PM haael <haael@interia.pl> wrote:

Very often I use the following construction (especially in operators):

     try:
         something
     except SomeError:
         try:
             something_else
         except AnotherError:
             try:
                 something_completely_different
             except Whatever:
                 return NotImplemented


I propose a construction to simplify the staircase hierarchy of
exception handlers:

     try:
         something
     except SomeError try:
         something_else
     except AnotherError try:
         something_completely_different
     except Whatever:
         return NotImplemented

This would be somewhat analogous to `else if` blocks.

This pattern is very common in operator implementations. And this
proposal could simplify it a bit.

haael
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/XNR5PVAFHTK5WO6P3GS2HCM7V6FPHQLH/
Code of Conduct: http://python.org/psf/codeofconduct/