Skip to main content

Command Palette

Search for a command to run...

Handling Multiple Exceptions with PHP 7.1

Updated
โ€ข1 min read
Handling Multiple Exceptions with PHP 7.1
P

I'm Pierre-Henry Soria. A passionate full stack engineer, building things that matter, making a real impact on the world.

Really like to take care of others and manage my workflow based on productivity methodologies.

Open to fast-paced changes with rapidly evolving business and technologies. I'm always thirsty to learn and undertake new exciting things and thrilling challenges.

Here is how you can handle easily multiple error 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 application from scratch is now available: https://www.udemy.com/course/create-real-world-php-webapp-from-scratch/

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

More from this blog

Super Passionate Software Engineer

37 posts

Pierre-Henry Soria. A super passionate & enthusiastic software engineer! ๐Ÿš€ True cheese & chocolate lover! ๐Ÿ˜‹ ๐Ÿ‘‰ Reach me at https://ph7.me ๐Ÿ’ซ