In the code below, I am getting the error :
enum errors: Error {
case too_short, too_obvs
}
func checkPassword(_ passwordEntered: String) throws -> String {
if passwordEntered.count < 5 {
throw errors.too_short
}
if passwordEntered == "12345" {
throw errors.too_obvs
}
if passwordEntered.count >= 10 {
return "Password set."
}
}
let myPassword = "12345"
do {
let result = try checkPassword(myPassword)
print("\(result) is your password rating.")
} catch errors.too_short { // customised catch
print("Password is too short.")
} catch errors.too_obvs {
print("A 5 yr old would guess that password!")
} catch { // default catch
print("Error. Enter a stronger password.")
print("Error: \(error.localizedDescription)") // -> to use default Swift error explanations
}
Error -
error: value of type 'Error' has no member 'localizedDescription'
print("Error: \(error.localizedDescription)") // -> to use default Swift error explanations
I don't understand why it's pointing out 'Error'
when it isn't even used in the print.
I do not understand what I am missing here. Any help will be appreciated. Thank you.