突然出现do/catch错误
Suddenly get do/catch error
我运行这段代码已经有一段时间了,但是它突然在下面抛出错误,为什么我没有编辑代码就突然得到这个?我在 do/catch 声明中做错了什么?
func addInput(device: AVCaptureDevice) {
do {
captureSession.addInput(try AVCaptureDeviceInput(device: device))
} catch let err as NSError {
print(err)
}
}
错误
Errors thrown from here are not handled because the enclosing catch is not exhaustive
存在 catch
有或没有 error
的可能性。只需添加一个新的 catch 语句。
do { /* try something */ }
catch let error { print((error as NSError)) }
catch { print("No error") }
如果您使用第二行中的版本,则可能不需要第三行。
我运行这段代码已经有一段时间了,但是它突然在下面抛出错误,为什么我没有编辑代码就突然得到这个?我在 do/catch 声明中做错了什么?
func addInput(device: AVCaptureDevice) {
do {
captureSession.addInput(try AVCaptureDeviceInput(device: device))
} catch let err as NSError {
print(err)
}
}
错误
Errors thrown from here are not handled because the enclosing catch is not exhaustive
存在 catch
有或没有 error
的可能性。只需添加一个新的 catch 语句。
do { /* try something */ }
catch let error { print((error as NSError)) }
catch { print("No error") }
如果您使用第二行中的版本,则可能不需要第三行。