Add try EXP catch EXP

This commit is contained in:
Nicolas Williams committed 2014-07-06 01:29:42 -05:00
1 parent 9113282c27
commit 7fce34292e
9 files changed
+108 -15

No files matched your search

+5
View File
@@ -665,6 +665,11 @@ def inc(x): x |= .+1; inc(.[].a)
{}
[true, true, false]
# Try/catch and general `?` operator
[.[]|try if . == 0 then error("foo") elif . == 1 then .a elif . == 2 then empty else . end catch .]
[0,1,2,3]
["foo","Cannot index number with string \"a\"",3]
# string operations
[.[]|startswith("foo")]
["fo", "foo", "barfoo", "foobar", "barfoob"]