I tried the following code, which is a valid loop, IMHO, since it
doesn't leave the catch clause.
(try
:xxx
(catch Exception e
(loop [x e]
(if (nil? (.getCause x))
x
(recur (.getCause x))))))
However I get:
java.lang.UnsupportedOperationException: Cannot recur from catch/
finally (NO_SOURCE_FILE:1)
Is this intended?
Sincerely
Meikel
I tried the following code, which is a valid loop, IMHO, since it
doesn't leave the catch clause.
(try
:xxx
(catch Exception e
(loop [x e]
(if (nil? (.getCause x))
x
(recur (.getCause x))))))
However I get:
java.lang.UnsupportedOperationException: Cannot recur from catch/finally (NO_SOURCE_FILE:1)
Is this intended?
Am 16.11.2008 um 18:55 schrieb Stephen C. Gilardi:
>> Is this intended?
> It is intended. Please see the discussion here:
>
> http://groups.google.com/group/clojure/search?group=clojure&q=recur+catch&qt_g=Search+this+group
I skimmed through the thread, and it seems the discussion is
for the following case:
(loop [...]
(try
...
(catch ... (recur ...))))
I wouldn't expect this to work. However in my case the structure
was:
(try
...
(catch ... (loop [...] (recur ...))))
So the loop did not cross the catch clause. From theoretic
point of view, I don't see a reason, why this should not be
possible. From a practical point of view there might be well
a reason why this prohibited. But then it should be mentioned
in the docs: "no loop inside catch".
Sincerely
Meikel
I skimmed through the thread, and it seems the discussion is
for the following case:
(loop [...]
(try
...
(catch ... (recur ...))))
I wouldn't expect this to work. However in my case the structure
was:
(try
...
(catch ... (loop [...] (recur ...))))
So the loop did not cross the catch clause. From theoretic
point of view, I don't see a reason, why this should not be
possible.
You could of course work around this by putting your loop in some
other function and calling it from inside catch.
--Chouser