【发布时间】:2015-09-29 21:37:12
【问题描述】:
我正在更新我的代码以使用 Swift,我想知道如何打印与“catch all”子句匹配的异常的错误详细信息。我对Swift Language Guide Page 中的示例稍作修改以说明我的观点:
do {
try vend(itemNamed: "Candy Bar")
// Enjoy delicious snack
} catch VendingMachineError.InvalidSelection {
print("Invalid Selection.")
} catch VendingMachineError.OutOfStock {
print("Out of Stock.")
} catch VendingMachineError.InsufficientFunds(let amountRequired) {
print("Insufficient funds. Please insert an additional $\(amountRequired).")
} catch {
// HOW DO I PRINT OUT INFORMATION ABOUT THE ERROR HERE?
}
如果我发现意外异常,我需要能够记录导致它的原因。
【问题讨论】: