mirror of
https://github.com/php/php-src.git
synced 2025-08-20 01:14:28 +02:00
This commit add the possibility to catch multiple exception types in
a single catch statement to avoid code duplication.
try {
// Some code...
} catch (ExceptionType1 | ExceptionType2 $e) {
// Code to handle the exception
} catch (\Exception $e) {
// ...
}
21 lines
322 B
PHP
21 lines
322 B
PHP
--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
|