On 02/07/2020 07:33 AM, Serhiy Storchaka wrote:
07.02.20 16:28, Ram Rachum пише:
The idea is to add `raise as` syntax, that raises an exception while setting 
the currently caught exception to be the cause. It'll look like this:

     try:
         1/0
     except ZeroDivisionError:
         raise as ValueError('Whatever')

What it does is a shorter version of this:

     try:
         1/0
     except ZeroDivisionError as error:
         raise ValueError('Whatever') from error

How does it differ from

     try:
         1/0
     except ZeroDivisionError:
         raise ValueError('Whatever')

Here's a diff:

$ diff no_from.py with_from.py
3,4c3,4
- ... except ZeroDivisionError:
- ...     raise ValueError('Whatever')
---
+ ... except ZeroDivisionError as e:
+ ...     raise ValueError('Whatever') from e
10c10
- During handling of the above exception, another exception occurred:
---
+ The above exception was the direct cause of the following exception:


To me the difference between "raise from" and "raise" is the implicit meaning:

- "During handling of ..." implies that the second exception should not have 
occurred and there is a bug in the exception handling code

- "The above exception ..." implies that this code path is normal and extra 
information is being supplied

Personally, my main use of "raise from" is "raise from None".


I'm -1 on the new syntax: to me it looks much more like a "raise ... from None".

--
~Ethan~
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@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/32GUE7J56XSYWHXJTAKUTVP3GT5ZGZSE/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to