在Swift中,我如何像这样在完成处理程序中引发错误:
let task = URLSession.shared.dataTask(with: request as URLRequest, completionHandler: {
(data, response, error) in
do {
//something
completion(result)
} catch let jsonError {
throw CustomError.myerror //THIS DOESN'T WORK
}
})
task.resume()
错误提示为
从抛出类型为“(_, _, _) throws -> ()”的函数到非抛出函数类型“(Data?, URLResponse?, Error?) -> Void”的转换无效。