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. Protection Status