Here is how you can handle easily multiple exceptions thanks to PHP 7.1.
π Source code of the example project https://gist.github.com/pH-7/5ba7f83a9e1befc46a68379301eec41e
Example
try {
$person = new Person('Pierre');
echo $person->greeting('morning'); // can be 'morning', 'afternoon', or 'evening'
} catch(InvalidNameException | InvalidDayMomentException $err) { // Catch multiple exceptions at once
echo $err->getMessage();
}
π My Udemy course on how to build a real-world PHP 8.1 application from scratch - https://www.udemy.com/course/create-real-world-php-webapp-from-scratch/
Top comments (0)