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 Error Handling in Swift Error Handling Cleaning Up With Defer

3 Answers

Matt Skelton
Matt Skelton
4,548 Points

That'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!

hannah echo
hannah echo
2,872 Points

throw isn't required here because of the use of the try keyword

Olivier Van hamme
Olivier Van hamme
5,418 Points

I 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 ?