rfc:non-capturing_catches
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:non-capturing_catches [2020/04/06 08:37] – ++ maxsem | rfc:non-capturing_catches [2020/04/06 20:07] – eh maxsem | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC: Your Title Here ====== | + | ====== PHP RFC: non-capturing catches |
* Version: 0.9 | * Version: 0.9 | ||
* Date: 2020-04-05 | * Date: 2020-04-05 | ||
Line 8: | Line 8: | ||
===== Introduction ===== | ===== Introduction ===== | ||
Currently, PHP requires to capture the exception being caught to a variable: | Currently, PHP requires to capture the exception being caught to a variable: | ||
- | <php> | + | <code php> |
try { | try { | ||
foo(); | foo(); | ||
Line 14: | Line 14: | ||
die($ex-> | die($ex-> | ||
} | } | ||
- | </php> | + | </code> |
However, you need to specify the variable even if it's not used: | However, you need to specify the variable even if it's not used: | ||
- | <php> | + | |
+ | <code php> | ||
try { | try { | ||
changeImportantData(); | changeImportantData(); | ||
Line 22: | Line 24: | ||
echo "You don't have permission to do this"; | echo "You don't have permission to do this"; | ||
} | } | ||
- | </php> | + | </code> |
Someone reading the above code is left to wonder if the author intended to not use the exception variable or it's a bug. | Someone reading the above code is left to wonder if the author intended to not use the exception variable or it's a bug. | ||
===== Proposal ===== | ===== Proposal ===== | ||
Allow catching exceptions without capturing them to variables: | Allow catching exceptions without capturing them to variables: | ||
- | <php> | + | <code php> |
try { | try { | ||
changeImportantData(); | changeImportantData(); | ||
Line 33: | Line 36: | ||
echo "You don't have permission to do this"; | echo "You don't have permission to do this"; | ||
} | } | ||
- | </php> | + | </code> |
===== Prior art ===== | ===== Prior art ===== | ||
+ | Such change was first proposed in [[https:// | ||
+ | <code php> | ||
+ | try { | ||
+ | foo(); | ||
+ | } catch { | ||
+ | bar(); | ||
+ | } | ||
+ | </ | ||
+ | Meanwhile what I'm proposing here has received mostly positive feedback so I feel it's worth trying. | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== |
rfc/non-capturing_catches.txt · Last modified: 2020/05/26 14:39 by maxsem