Challenge: Exception Handling
Explore how to implement exception handling in PHP object-oriented programming by adding validation checks to user input methods. Learn to throw and catch exceptions for invalid user names and ages, and handle errors gracefully with informative messages. This lesson helps you improve your error management skills for more reliable PHP applications.
We'll cover the following...
We'll cover the following...
Task
You are given a User class with the methods that set and get the user name and age.
- Add code to the
setName()method that throws the exception“The name should be at least 3 characters long”whenever the user’s name is shorter