catch let error as LocksmithError{
print(error)// it would print the case of the error.
}
但是如果我这样做
catch LocksmithError.Duplicate{
}
catch{
print (LocksmithError) // Obviously I would just print LocksmithError, it won't print the case
print (LocksmithError.rawValue) // prints nothing
}
我的问题是:使用第二种方法是否有任何我可以实际检索的内容以及错误的值/情况?或者,如果我没有在入口点(即捕获点)获得正确的值,那么我就会错过这样做的机会!
The catch
块是排他性的情况,按顺序评估。当比赛成功时,我们stop.
那么,让我们考虑一下这个结构:
catch LocksmithError.Duplicate {
// 1
print("duplicate")
}
catch {
// 2
print(error)
}
如果我们在1,那么范围内就是LocksmithError.Duplicate
.
如果我们在2,那么范围内就是 everyother一种被捕获的错误。你没有办法抓住LocksmithError.Duplicate
在这里,因为前假设它会被困在1我们不会be here.
现在,方法I会这样做是这样的:
catch let err as LocksmithError {
// 1
print(err)
}
catch {
// 2
print(error)
}
这可能就是你所追求的东西;它给了我们一个价值err
将错误带入大括号中1。 (自动error
价值只存在最后的包罗万象catch
block.)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)