parent
d0cb1395e5
commit
bc6d15c81a
5 changed files with 139 additions and 41 deletions
@ -0,0 +1,30 @@ |
|||||||
|
--TEST-- |
||||||
|
exception thrown inside catch is not handled by sibling catch |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
class FinallySiblingA extends Exception {} |
||||||
|
class FinallySiblingB extends Exception {} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
try { |
||||||
|
try { |
||||||
|
throw new FinallySiblingA("a"); |
||||||
|
} catch (FinallySiblingA $e) { |
||||||
|
echo "catch-a\n"; |
||||||
|
throw new FinallySiblingB("b"); |
||||||
|
} catch (FinallySiblingB $e) { |
||||||
|
echo "catch-b\n"; |
||||||
|
} finally { |
||||||
|
echo "finally\n"; |
||||||
|
} |
||||||
|
} catch (FinallySiblingB $e) { |
||||||
|
echo "outer:" . $e->getMessage() . "\n"; |
||||||
|
} |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
catch-a |
||||||
|
finally |
||||||
|
outer:b |
||||||
@ -0,0 +1,26 @@ |
|||||||
|
--TEST-- |
||||||
|
finally must not see variables from unmatched catch clauses |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
class FinallyUnmatchedA extends Exception {} |
||||||
|
class FinallyUnmatchedB extends Exception {} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
try { |
||||||
|
try { |
||||||
|
throw new FinallyUnmatchedA("a"); |
||||||
|
} catch (FinallyUnmatchedB $e) { |
||||||
|
echo "catch-b\n"; |
||||||
|
} finally { |
||||||
|
echo isset($e) ? "set\n" : "unset\n"; |
||||||
|
} |
||||||
|
} catch (FinallyUnmatchedA $e) { |
||||||
|
echo "outer:" . $e->getMessage() . "\n"; |
||||||
|
} |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
unset |
||||||
|
outer:a |
||||||
@ -1,29 +1,26 @@ |
|||||||
--TEST-- |
--TEST-- |
||||||
try-catch-finally: finally block must execute when exception is re-thrown inside catch block. Verifies that finally can access the caught exception variable ($e) even when the catch block re-throws it. |
finally can use caught exception variable when catch rethrows |
||||||
--FILE-- |
--FILE-- |
||||||
<?php |
<?php |
||||||
function main() { |
|
||||||
try { |
function main(): void |
||||||
$a = 1; |
{ |
||||||
throw new RuntimeException('test'); |
try { |
||||||
return 0; // trigger bug |
$a = 1; |
||||||
} catch (\Throwable $e) { |
throw new RuntimeException('test'); |
||||||
echo 'Caught exception: ', $e->getMessage(), "\n"; |
return; |
||||||
throw $e; |
} catch (Throwable $e) { |
||||||
} finally { |
echo 'Caught exception: ', $e->getMessage(), "\n"; |
||||||
var_dump($a); |
throw $e; |
||||||
echo 'Finally exception: ', $e->getMessage(), "\n"; |
} finally { |
||||||
} |
var_dump($a); |
||||||
var_dump('This should not be reached'); |
echo 'Finally exception: ', $e->getMessage(), "\n"; |
||||||
} |
} |
||||||
?> |
} |
||||||
--EXPECT-- |
?> |
||||||
Caught exception: test |
--EXPECTF-- |
||||||
int(1) |
Caught exception: test |
||||||
Finally exception: test |
int(1) |
||||||
|
Finally exception: test |
||||||
Fatal error: Uncaught RuntimeException: test in Unknown(0) : eval():1 |
|
||||||
Stack trace: |
Fatal error: Uncaught RuntimeException: test in %A |
||||||
#0 Unknown(0) : eval()(1): main() |
|
||||||
#1 {main} |
|
||||||
thrown in Unknown(0) : eval() on line 1 |
|
||||||
|
|||||||
@ -0,0 +1,31 @@ |
|||||||
|
--TEST-- |
||||||
|
multi-catch conditions respect catch match state with finally |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
class FinallyMultiCatchA extends Exception {} |
||||||
|
class FinallyMultiCatchB extends Exception {} |
||||||
|
class FinallyMultiCatchC extends Exception {} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
try { |
||||||
|
try { |
||||||
|
throw new FinallyMultiCatchA("a"); |
||||||
|
} catch (FinallyMultiCatchA|FinallyMultiCatchB $e) { |
||||||
|
echo "catch-ab\n"; |
||||||
|
throw new FinallyMultiCatchC("c"); |
||||||
|
} catch (FinallyMultiCatchC $e) { |
||||||
|
echo "catch-c\n"; |
||||||
|
} finally { |
||||||
|
echo "finally\n"; |
||||||
|
} |
||||||
|
} catch (FinallyMultiCatchC $e) { |
||||||
|
echo "outer:" . $e->getMessage() . "\n"; |
||||||
|
} |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
catch-ab |
||||||
|
finally |
||||||
|
outer:c |
||||||
Loading…
Reference in new issue