You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pannous edited this page Feb 19, 2021
·
1 revision
The try keyword, similar to Ruby, extends the simple Java mechanism and even the advanced Swift mechanism:
Instead of
guard let item = inventory[name] else {
throw VendingMachineError.invalidSelection
}
Angle gives you
try item = inventory[name] else invalidSelection
Once an error is assigned to a variable (item), it behaves like an unfulfilled optional:
calling e.g. item.count without elvis operator .? activates the throwing of the exception, in this case the invalidSelection Error.