Exceptions/Catch an exception thrown in a nested call: Difference between revisions
Exceptions/Catch an exception thrown in a nested call (view source)
Revision as of 09:05, 15 November 2014
, 9 years agojq
m ({{Task|Control Structures}}) |
(jq) |
||
Line 1,421:
<pre>caught exception U0
uncaught exception: U1</pre>
=={{header|jq}}==
{{works with|jq|>1.4}}
<lang jq># n is assumed to be the number of times baz has been previously called:
def baz(n):
if n==0 then error("U0")
elif n==1 then error("U1")
else "Goodbye"
end;
def bar(n): baz(n);
def foo:
(try bar(0) catch if . == "U0" then "We caught U0" else error(.) end),
(try bar(1) catch if . == "U0" then "We caught U0" else error(.) end);
foo</lang>
{{out}}
$ jq -n -f Catch_an_exception_thrown_in_a_nested_call.jq
"We caught U0"
jq: error: U1
=={{header|Lasso}}==
|