class Car{}
struct Exception: Error {
var message: String
}
class Seller {
var cars: [Car] = [Car]()
func sell() throws {
if cars.isEmpty {
throw Exception(message: "No cars for sale")
}
}
}
let seller = Seller()
do {
try seller.sell()
}
catch let e as Exception {
print(e.message)
//e.message is "No cars for sale"
}
catch {}