Exceptions/Catch an exception thrown in a nested call: Difference between revisions

Add Julia language
(Removing C Omit as implementation exists and is working properly.)
(Add Julia language)
Line 1,685:
"We caught U0"
jq: error: U1
 
=={{header|Julia}}==
{{works with|Julia|0.6}}
 
<lang julia>struct U0 <: Exception end
struct U1 <: Exception end
 
function foo()
for i in 1:2
try
bar()
catch err
if isa(err, U0) println("catched U0")
else rethrow(err) end
end
end
end
 
function bar()
baz()
end
 
function baz()
if isdefined(:_called) && _called
throw(U1())
else
global _called = true
throw(U0())
end
end
 
foo()</lang>
 
{{out}}
<pre>catched U0
LoadError: U1()
while loading /home/giovanni/documents/workspace/julia/Rosetta-Julia/src/Catch_an_exception_thrown_in_a_nested_call.jl, in expression starting on line 31
in foo at Rosetta-Julia/src/Catch_an_exception_thrown_in_a_nested_call.jl:10
in baz at Rosetta-Julia/src/Catch_an_exception_thrown_in_a_nested_call.jl:24</pre>
 
=={{header|Kotlin}}==
Anonymous user