Exceptions are over/mis-used in java, particularly checked exceptions
(runtime exceptions aren't so bad).  My sense is that those places
where java.lang.Exception is thrown, the exception is not expected to
be handled by user code, or perhaps more accurately, a direct result
of a bug fat-fingered into the user code, e.g.:
user=> (+ 5 foo)
java.lang.Exception: Unable to resolve symbol: foo in this context
(NO_SOURCE_FILE:1)

While there's little to no value in "handling" such a case at runtime,
there is value in the exception message that can be used to debug the
problem in the code.

Note also that the behavior is different when user code does the
resolution on a :
user=> (resolve (symbol "foo"))
nil

There are only a handful of functions that are documented to throw an
exception, and none of them are checked exceptions.


On Mar 13, 9:40 am, CloudiDust <cloudid...@gmail.com> wrote:
> Greetings everyone!
>
> I am currently beginning to learn clojure, and here's one thing that I
> don't quite understand, that many exceptions thrown by clojure are the
> most generic java.lang.Exception's (e.g. when a symbol cannot be
> resolved). Why aren't more specific exception classes used, like
> clojure.lang.SymbolResolutionException? (Having a more specific
> exception class seems useful when doing exception handling.)
>
> As far as I know, clojure throws exceptions defined in the standard
> Java library only, like the IllegalStateException when updating refs
> outside a transaction. So there are no appropriate exception classes
> for some errors occurred in clojure, which may be the reason it falls
> back to java.lang.Exception.
>
> Is the standard-exception-only thing intentional? If so, would you
> please tell me the rationale behind such a decision?
>
> I have only played with clojure for one day, so there's a huge
> possibility that I missed or misunderstood something.
>
> Please enlighten me. Thanks in advance. :)
>
> Regards,
> Ruochen

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to