Exceptions: Difference between revisions
Content deleted Content added
No edit summary |
No edit summary |
||
Line 627:
`catchDyn` \ex -> do
{- handle exception "ex" here -}</lang>
=={{header|Icon}} and {{header|Unicon}}==
The following Unicon example makes use of support for exceptions found in the
Unilib package.
<lang Unicon>import Exceptions
procedure main(A)
every i := !A do {
case Try().call{ write(g(i)) } of {
Try().catch(): {
x := Try().getException()
write(x.getMessage(), ":\n", x.getLocation())
}
}
}
end
procedure g(i)
if numeric(i) = 3 then Exception().throw("bad value of "||i)
return i
end</lang>
A sample run is:
<pre>
-> ExceptionTest 1 2 3 4 5
1
2
Exception: bad value of 3:
procedure g [ExceptionTest.icn:15]
procedure main [ExceptionTest.icn:5]
4
5
->
</pre>
=={{header|J}}==
|