PHP 7.1 – Catching Multiple Exception Types

We general use PHP’s try..catch blocks to handle exceptions. If the try block could cause one of several different exceptions they can each be handled separately with their own catch section. As shown below

If you observe the above example, we are handling the all the exceptions in the same way and we are duplicating the code of each catch statement.

PHP 7.1 introduces the possibility to catch multiple exception types in a single catch statement to avoid code duplication. Below is the example –

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

Arjun
I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.
DMCA.com Protection Status