Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Lorenzo 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