Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
We can throw exceptions to let our users know when things don't work quite right.
Throwing Exceptions
First we need to tell our Course class to use \App\Exception\ApiException;
. Then we can throw exceptions to let our users know what's going on.
We should throw and exception in the following situations:
- With getCourses
- if there are no courses
- With getCourse
- if we can't find a course
- With createCourse
- check that the proper data has been passed
- check if the course has actually been added
- With updateCourse
- check if the proper data has been passed
- check if the course has actually been added
- check if the course exists before trying to add the course. Instead of writing this again here, we can use the getCourse method
- With deleteCourse
- check if the course exists first. Again we can use getCourse
- check that the database has been affected by our statement
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up