PHP Exceptions
In this code snippet, we’ll learn how to throw and handle an exception in PHP. Exceptions are used to indicate that an error has occurred within our code. For this demo, we’ll make a simple function that returns the sum of all the elements in a given array. But if the array is empty we’ll throw an exception. We’ll also check the data type of each element using gettype() to make sure the provided value is in fact a number, else an exception will be thrown.