[RFC] Multiple catch #1796
Closed
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f868308
Multiple exceptions type in a single catch statement
adoy e09d233
Move tests
adoy 8a48732
Remove useless check we should always have an exception
adoy a6a7909
Fix CS
adoy 36959f9
Add one test for nested try catch with multicatch
adoy cb8c3de
Revert "Remove useless check we should always have an exception"
adoy
Jump to file
+5
−0
exceptions.inc
Zend/tests/try/exceptions.inc
+19
−0
try_multicatch_001.phpt
Zend/tests/try/try_multicatch_001.phpt
+21
−0
try_multicatch_002.phpt
Zend/tests/try/try_multicatch_002.phpt
+21
−0
try_multicatch_003.phpt
Zend/tests/try/try_multicatch_003.phpt
+21
−0
try_multicatch_004.phpt
Zend/tests/try/try_multicatch_004.phpt
+25
−0
try_multicatch_005.phpt
Zend/tests/try/try_multicatch_005.phpt
+6
−3
zend_ast.c
Zend/zend_ast.c
+39
−19
zend_compile.c
Zend/zend_compile.c
+7
−2
zend_language_parser.y
Zend/zend_language_parser.y
| @@ -0,0 +1,5 @@ | ||
| +<?php | ||
| + | ||
| +class Exception1 extends Exception {} | ||
| +class Exception2 extends Exception {} | ||
| +class Exception3 extends Exception {} |
| @@ -0,0 +1,19 @@ | ||
| +--TEST-- | ||
| +Parsing test | ||
| +--FILE-- | ||
| +<?php | ||
| + | ||
| +require_once __DIR__ . '/exceptions.inc'; | ||
| + | ||
| +try { | ||
| + echo 'TRY' . PHP_EOL; | ||
| +} catch(Exception1 | Exception2 $e) { | ||
| + echo 'Exception'; | ||
| +} finally { | ||
| + echo 'FINALLY' . PHP_EOL; | ||
| +} | ||
| + | ||
| +?> | ||
| +--EXPECT-- | ||
| +TRY | ||
| +FINALLY |
| @@ -0,0 +1,21 @@ | ||
| +--TEST-- | ||
| +Catch first exception in the multicatch | ||
| +--FILE-- | ||
| +<?php | ||
| + | ||
| +require_once __DIR__ . '/exceptions.inc'; | ||
| + | ||
| +try { | ||
| + echo 'TRY' . PHP_EOL; | ||
| + throw new Exception1; | ||
| +} catch(Exception1 | Exception2 | Exception3 $e) { | ||
| + echo get_class($e) . PHP_EOL; | ||
| +} finally { | ||
| + echo 'FINALLY' . PHP_EOL; | ||
| +} | ||
| + | ||
| +?> | ||
| +--EXPECT-- | ||
| +TRY | ||
| +Exception1 | ||
| +FINALLY |
| @@ -0,0 +1,21 @@ | ||
| +--TEST-- | ||
| +Catch second exception in the multicatch | ||
| +--FILE-- | ||
| +<?php | ||
| + | ||
| +require_once __DIR__ . '/exceptions.inc'; | ||
| + | ||
| +try { | ||
| + echo 'TRY' . PHP_EOL; | ||
| + throw new Exception2; | ||
| +} catch(Exception1 | Exception2 | Exception3 $e) { | ||
| + echo get_class($e) . PHP_EOL; | ||
| +} finally { | ||
| + echo 'FINALLY' . PHP_EOL; | ||
| +} | ||
| + | ||
| +?> | ||
| +--EXPECT-- | ||
| +TRY | ||
| +Exception2 | ||
| +FINALLY |
| @@ -0,0 +1,21 @@ | ||
| +--TEST-- | ||
| +Catch last exception in the multicatch | ||
| +--FILE-- | ||
| +<?php | ||
| + | ||
| +require_once __DIR__ . '/exceptions.inc'; | ||
| + | ||
| +try { | ||
| + echo 'TRY' . PHP_EOL; | ||
| + throw new Exception3; | ||
| +} catch(Exception1 | Exception2 | Exception3 $e) { | ||
| + echo get_class($e) . PHP_EOL; | ||
| +} finally { | ||
| + echo 'FINALLY' . PHP_EOL; | ||
| +} | ||
| + | ||
| +?> | ||
| +--EXPECT-- | ||
| +TRY | ||
| +Exception3 | ||
| +FINALLY |
| @@ -0,0 +1,25 @@ | ||
| +--TEST-- | ||
| +Catch exception in the nested multicatch | ||
| +--FILE-- | ||
| +<?php | ||
| + | ||
| +require_once __DIR__ . '/exceptions.inc'; | ||
| + | ||
| +try { | ||
| + try { | ||
| + echo 'TRY' . PHP_EOL; | ||
| + throw new Exception3; | ||
| + } catch (Exception1 | Exception3 $e) { | ||
| + echo get_class($e) . PHP_EOL; | ||
| + } | ||
| +} catch(Exception2 | Exception3 $e) { | ||
| + echo 'Should never be executed'; | ||
| +} finally { | ||
| + echo 'FINALLY' . PHP_EOL; | ||
| +} | ||
| + | ||
| +?> | ||
| +--EXPECT-- | ||
| +TRY | ||
| +Exception3 | ||
| +FINALLY |