From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

Thrown errors

Thrown errors

- [Instructor] There's many ways to handle errors in Swift, for some errors, using throws is a great way to handle errors without crashing the system. Download the exercise file and you'll find a project with an embedded playground. Go into the playground and we can close everything else up to make it all nice and clean and easy to read and you'll see, we have a small program here that, while there's a lot better ways to do this, I'm going to use an example of a function called coffee that finds the rating of a type of coffee using two arrays. You'll notice that there's some Index Out of Range errors possible here in the rating and the search. We have five elements in coffees and only four in ratings, so this Kona element is going to give us an error, we've got a negative one here in the ratings and you'll notice that we have a rating down here for count, using the string repeating and that'll give an error, so we got plenty of errors and the Error Not Found for the coffees, that'll…

Contents