错误处理

enum ExceptionError {
    case isNil, isEmpty
}

func throwWhenNilOrEmpty(_ array: [Int]?) throws {
    if array == nil {
        throw Exception.isNil
    }
    if array!.isEmpty {
        throw Exception.isEmpty
    }
}

do {
    try throwWhenNilOrEmpty(nil)
}
catch {
    print("Error happened")
}