On Oct 23, 10:11 pm, jim <[EMAIL PROTECTED]> wrote:
> Rich,
>
> When I do the following:
>
> (gen-and-load-class 'user.UserException :extends Exception)
>
> (defn th [arg]
> (throw (new user.UserException "thrown exception")))
>
> (defn test-fn []
> (try
> (dorun (map th '(1 2 3)))
> (catch user.UserException e
> (println "caught" e))
> (finally (println "finally clause"))))
>
> and then execute test-fn, the exception is not caught.
>
> user=> (test-fn)
> finally clause
> java.lang.RuntimeException: user.UserException: thrown exception
> (NO_SOURCE_FILE:0)
>
> So am I doing something wrong or is this a bug when an exception is
> thrown from inside a call to map?
>
Currently ISeq (the interface for seqs) doesn't declare any exceptions
on first/rest, therefor no implementations, e.g. LazyCons, can throw
checked exceptions. So, if they encounter an exception in the
implementation closure, they have to wrap it in an unchecked
exception, like RuntimeException.
This is a good example of why checked exceptions are bad - they force
intervening parties who should have no participation in the process to
be involved in exception declarations and handling, thereby thwarting
the basic premise of exceptions - communication between the party that
had the problem and the party that can do something about it.
In any case, the only way to fix this is to declare that first/rest
throw Exception in ISeq, which would be a big change (because
everything that calls them would then have to declare exceptions, and
everything that calls them... - complete inanity).
They definitely weren't thinking about closures and higher-order
programming when they invented checked exceptions - it invariably
leads to everything declaring they throw the root Exception, so why
bother?
Rich
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---