Looked more into how error handling works in Swift.
Every function that can throw hast to be prepended with a try
statement.
Every function that can throw errors has to be marked with the throws
statement.
I can check for different errors like this:
do {
try shop.order(itemNamed: "Black Shirt", amount: 26)
print("Ordered Black Shirts")
} catch OnlineShopError.outOfStack {
print("Not enough shirts in stock.")
}
catch OnlineShopError.invalidSelection {
print("Selection was invalid")
}
I can convert errors to optional values like
let a = try? errorThrowingFunc()