다음과 같이 "/"로 구분하고 빈칸 없이 입력해주세요.
ex) 빈칸1/빈칸2/빈칸3/빈칸4/빈칸5
enum VendingMachineError: _____빈칸1_____ {
case invalidInput
case insufficientFunds(moneyNeeded: Int)
case outOfStock
}
class VendingMachine {
var deposited: Int = 0
func receiveMoney(_ money: Int) throws {
guard money > 0 else {
_____빈칸2_____ VendingMachineError.invalidInput
}
self.deposited += money
print("\(money)원 받음")
}
}
let machine: VendingMachine = VendingMachine()
_____빈칸3_____ {
_____빈칸4_____ machine.receiveMoney(0)
} _____빈칸5_____ VendingMachineError.invalidInput {
print("입력이 잘못되었습니다")
} catch VendingMachineError.insufficientFunds(let moneyNeeded) {
print("\(moneyNeeded)원이 부족합니다")
} catch VendingMachineError.outOfStock {
print("수량이 부족합니다")
}
정답 : Error/throw/do/try/catch