forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support catching exceptions without capturing them to variables
RFC: https://wiki.php.net/rfc/non-capturing_catches Closes phpGH-5345.
- Loading branch information
Showing
8 changed files
with
87 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--TEST-- | ||
catch without capturing a variable | ||
--FILE-- | ||
<?php | ||
|
||
try { | ||
throw new Exception(); | ||
} catch (Exception) { | ||
echo "Exception\n"; | ||
} | ||
|
||
try { | ||
throw new Exception(); | ||
} catch (Exception) { | ||
echo "Exception\n"; | ||
} catch (Error) { | ||
echo "FAIL\n"; | ||
} | ||
|
||
try { | ||
throw new Exception(); | ||
} catch (Exception|Error) { | ||
echo "Exception\n"; | ||
} catch (Throwable) { | ||
echo "FAIL\n"; | ||
} | ||
|
||
--EXPECT-- | ||
Exception | ||
Exception | ||
Exception |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--TEST-- | ||
catch without capturing a variable - exception in destructor | ||
--FILE-- | ||
<?php | ||
class ThrowsOnDestruct extends Exception { | ||
public function __destruct() { | ||
echo "Throwing\n"; | ||
throw new RuntimeException(__METHOD__); | ||
} | ||
} | ||
try { | ||
throw new ThrowsOnDestruct(); | ||
} catch (Exception) { | ||
echo "Unreachable catch\n"; | ||
} | ||
echo "Unreachable fallthrough\n"; | ||
|
||
?> | ||
--EXPECTF-- | ||
Throwing | ||
|
||
Fatal error: Uncaught RuntimeException: ThrowsOnDestruct::__destruct in %s:%d | ||
Stack trace: | ||
#0 %s(%d): ThrowsOnDestruct->__destruct() | ||
#1 {main} | ||
thrown in %s on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters