Skip to content
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.

Instead of

        guard item.count > 0 else {
            throw VendingMachineError.outOfStock
        }

In the assert macro, the else block is implicitly throwing:

assert item.count > 0 else outOfStock

Home

Philosophy

data & code blocks

features

inventions

evaluation

keywords

iteration

tasks

examples

todo : bad ideas and open questions

⚠️ specification and progress are out of sync

Clone this wiki locally