Handling Multiple Exceptions with PHP 7.1

Handling Multiple Exceptions with PHP 7.1

ยท

1 min read

Here is how you can handle easily multiple error exceptions thanks to PHP 7.1!

๐Ÿ‘‰ Source code of the example project gist.github.com/pH-7/5ba7f83a9e1befc46a6837..

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 application from scratch is now available: udemy.com/course/create-real-world-php-weba..

๐Ÿ‘‰ My GitHub github.com/pH-7 where I regularly publish packages, libraries, and proof of concepts.

ย