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 trialLorenzo Gonzalez
iOS Development Techdegree Student 4,648 PointsAbsence of "throw"
Why isn't there a "throw" in the second guard statement in this example?
3 Answers
Matt Skelton
4,548 PointsThat's a really good spot in my opinion. To my understanding, the guard statement you're referring to should be preceded with the throw keyword.
For reference for anybody interested:
func process(file name: String) throws {
guard isValidFile(withName: name) else {
throw ReadError.invalidFile // <--- throw keyword present
}
let file = open(fileName: name)
guard let line = try file.readLine() else {
ReadError.unableToReadLine // <--- throw keyword missing
}
}
Good vision!
Lorenzo Gonzalez
iOS Development Techdegree Student 4,648 PointsThanks for providing the code snippet!
hannah echo
2,872 Pointsthrow isn't required here because of the use of the try keyword
Shaan Marok
Courses Plus Student 1,015 Pointsit's a typo. It should be there.
Olivier Van hamme
5,418 PointsI agree. It must be a typo. At 2:02 Pasan is talking about the second throw statement. He literary mentions it:
From the video transcript:
" … Or in the case of the second throw statement, when we immediately hid that … "
Copy pasting this from the transcript, I discovered another typo: hid instead of hit ?
Jeff McDivitt
23,970 PointsJeff McDivitt
23,970 PointsCan you provide the code that you are referring to?
Thanks
Jeff