Message164184
| Author |
Tyler.Crompton |
| Recipients |
Tyler.Crompton |
| Date |
2012年06月27日.18:27:42 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1340821665.84.0.121596566188.issue15209@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
As you know, a caught exception can be re-raised with a simple `raise` statement. Plain and simple. However, one cannot re-raise an error with this new `"from" expression` clause.
For example:
def getch(prompt=''):
'''Get and return a character (similar to `input()`).'''
print(prompt, end='')
try:
return windows_module.getch()
except NameError:
try:
fallback_module.getch()
except Exception:
raise from None
Output:
File "getch.py", line 11
raise from None
^
SyntaxError: invalid syntax
A quick look at the documentation about [raise](http://docs.python.org/dev/reference/simple_stmts.html#the-raise-statement) confirms that this is the intended behavior. In my opinion, one should be able to still re-raise from an expression. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2012年06月27日 18:27:46 | Tyler.Crompton | set | recipients:
+ Tyler.Crompton |
| 2012年06月27日 18:27:45 | Tyler.Crompton | set | messageid: <1340821665.84.0.121596566188.issue15209@psf.upfronthosting.co.za> |
| 2012年06月27日 18:27:44 | Tyler.Crompton | link | issue15209 messages |
| 2012年06月27日 18:27:43 | Tyler.Crompton | create |
|