Catch all exceptions in Swift
enum Exception: ErrorType {
case isNil, isEmpty
}
func throwWhenNilOrEmpty(array: [Int]?) throws {
if array == nil {
throw Exception.isNil
}
if array?.count == 0 {
throw Exception.isEmpty
}
}
do {
try throwWhenNilOrEmpty(nil)
}
catch {
print("Error happened")
}
- Log in to post comments