4 ms·
But that's exactly what typed throws do? `static func validate(name: String) throws(ValidationError)` Would be handled as: ``` do { try UsernameValidat
by dep_b 1y ago
But that's exactly what typed throws do?
`static func validate(name: String) throws(ValidationError)`
Would be handled as:
```
do {
try UsernameValidator.validate(name: name)
} catch {
switch error {
case .emptyName:
print("You've submitted an empty name!")
case .nameTooShort(let nameLength):
print("The submitted name is too short!")
}
}
```
See: https://www.avanderlee.com/swift/typed-throws/ https://www.avanderlee.com/swift/typed-throws/
- bze12 1y agoOh I see, the original article didn’t use this syntax.