Skip to content

Instantly share code, notes, and snippets.

@Terriermon
Last active August 13, 2020 02:53
Show Gist options
  • Select an option

  • Save Terriermon/662c4c7372c61fa10ffed2cbc34c198d to your computer and use it in GitHub Desktop.

Select an option

Save Terriermon/662c4c7372c61fa10ffed2cbc34c198d to your computer and use it in GitHub Desktop.
var vendingMachine = VendingMachine()
vendingMachine.coinsDeposited = 8
do {
try buyFavoriteSnack(person: "Alice", vendingMachine: vendingMachine)
print("Success! Yum.")
} catch VendingMachineError.invalidSelection {
print("Invalid Selection.")
} catch VendingMachineError.outOfStock {
print("Out of Stock.")
} catch VendingMachineError.insufficientFunds(let coinsNeeded) {
print("Insufficient funds. Please insert an additional \(coinsNeeded) coins.")
} catch {
print("Unexpected error: \(error).")
}
// Prints "Insufficient funds. Please insert an additional 2 coins."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment