Exceptions/Catch an exception thrown in a nested call: Difference between revisions
Content added Content deleted
(→{{header|Elixir}}: version up (display message)) |
|||
Line 2,132: | Line 2,132: | ||
in sub foo at catch:4 |
in sub foo at catch:4 |
||
in block at catch:14</pre> |
in block at catch:14</pre> |
||
=={{header|Phix}}== |
|||
Phix does not have "exception classes" as such, instead you can just throw any string (on it's own) or any integer, optionally |
|||
with any (deeply nested) user_data that you like. All exceptions are always caught, however rethrowing is trivial.<br> |
|||
As per the discussion for Go, I should say that "bar(); bar();" cannot work - if you catch an exception from the first call, |
|||
control resumes within the catch handler, with no way to invoke that second bar(). But a simple loop does the trick. |
|||
<lang Phix>constant U0 = 0, |
|||
U1 = 1 |
|||
integer count = 0 |
|||
procedure baz() |
|||
count += 1 |
|||
if count=1 then |
|||
throw(U0,{{"any",{{"thing"},"you"}},"like"}) |
|||
else |
|||
throw(U1) |
|||
end if |
|||
end procedure |
|||
procedure bar() |
|||
baz() |
|||
end procedure |
|||
procedure foo() |
|||
for i=1 to 2 do |
|||
try |
|||
bar() |
|||
catch e |
|||
if e[E_CODE]=U0 then |
|||
?e[E_USER] |
|||
else |
|||
throw(e) -- (terminates) |
|||
end if |
|||
end try |
|||
puts(1,"still running...\n") |
|||
end for |
|||
puts(1,"not still running...\n") |
|||
end procedure |
|||
foo()</lang> |
|||
{{out}} |
|||
<pre> |
|||
{{"any",{{"thing"},"you"}},"like"} |
|||
still running... |
|||
C:\Program Files (x86)\Phix\test.exw:27 in procedure foo() |
|||
unhandled exception |
|||
i = 2 |
|||
e = {1,7533630,11,847,"baz","test.exw","C:\\Program Files (x86)\\Phix\\"} |
|||
... called from C:\Program Files (x86)\Phix\test.exw:35 |
|||
Global & Local Variables |
|||
--> see C:\Program Files (x86)\Phix\ex.err |
|||
Press Enter... |
|||
</pre> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |