enum Exception: Error {
case isNil, isEmpty
}
func throwWhenNilOrEmpty(_ array: [Int]?) throws {
if array == nil {
throw Exception.isNil
}
if array!.isEmpty {
throw Exception.isEmpty
}
}
do {
let array = [Int]()
try throwWhenNilOrEmpty(array)
}
catch Exception.isNil {
print("array is not specified")
}
catch Exception.isEmpty {
print("array is empty")
}
catch {}
//or
do {
try throwWhenNilOrEmpty(nil)
}
catch Exception.isNil, Exception.isEmpty {
print("please pass an array")
}
catch {}