December Code

December Code / Try Swift

Try Swift

No account needed. Answer, see why, move on.

1 of 3 today

Error Handlingeasy

What does this Swift code print?

enum PinError: Error {
    case tooShort
}

func check(_ p: String) throws -> String {
    if p.count < 4 {
        throw PinError.tooShort
    }
    return "ok"
}

do {
    print(try check("123"))
} catch {
    print("error:", error)
}
Choose one option
choose an option

Nothing here is saved. Create a free account to keep your progress, take an assessment and get your readiness score.