Handling Exceptions4:23 with Alena Holligan
What happens when the system is unable to connect to the database? Whenever your code relies on an external system, there's always the chance that something could go wrong. These are known as exceptions and any code connecting to an external system needs to handle them.
Although exception handling works in both PHP 5 and PHP 7, they will display slightly different exceptions. This means that the exact error text displayed could be different then what you see in the video, depending on which version of PHP you are running. This does not affect functionality and you should be able to follow along in any version of PHP 5 or above. PHP 7 introduced more precise exceptions. Instead of just throwing a generic exception, PHP 7 will also specify if this is an ArithmeticError, DivisionByZeroError, AssertionError, ParseError, or TypeError.
To learn more about the changes in PHP 7, check out our
Introduction to PHP 7 Workshop
You need to sign up for Treehouse in order to download course files.Sign up