Last active
August 13, 2020 02:53
-
-
Save Terriermon/662c4c7372c61fa10ffed2cbc34c198d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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