mixed.j
use io;
def struct StockError { kind as string, message as string, sku as string };
func reserve(sku as string) {
if ($sku == "") {
throw Error{kind: "stock", message: "no sku"};
}
throw StockError{kind: "stock", message: "sold out", sku: $sku};
}
for (def sku in ["T-42", ""]) {
try {
reserve($sku);
} catch (e) {
if ($e.kind == "stock") {
io.printf("sold out: %s\n", $e.sku);
}
}
}