Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Vending Machine App in Swift Displaying Additional Views Comparing Answers

Johnny Nguyen
Johnny Nguyen
3,875 Points

Pasan's mistake

if you put the code:

catch VendingMachineError.invalidSelection

then it doesn't work. You have to put into the else clause

Tagging: Pasan Premaratne

1 Answer

This isn't a mistake. Here Pasan is using invalidSelection to guard against a non valid selection being passed in to the Vend function. In other words, it's not being used to guard against "no selection".

However, you are correct in that you may also want to add a similar alert in the else clause for when nothing has been selected. Note: This would NOT be triggered by a catch statement though, so I assume he will be addressing this later.