trycatch.j
use io;
use json;
use strings;
func parse(text as string) {
try {
return json.decode($text);
} catch (e) {
if ($e.kind == "limit") {
io.printf("too big or too deep: %s\n", $e.message);
} else {
io.printf("%s: %s\n", $e.kind, $e.message);
}
}
return null;
}
parse('[1, 2, 3, 4,');
parse(strings.replicate("[", 5000));