On Mon, Mar 15, 2010 at 06:50, ataggart <alex.tagg...@gmail.com> wrote:
> 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)

That's my impression too. Unfortunately it's inconsistent with Java
convention. Java generally uses (extensions of) RuntimeException for
such cases. Other extensions of Exception are reserved for cases you
*are* expected to handle.

The fact that Clojure frees us from the tyranny of checked exceptions
is nice. The fact that it then turns around and uses what are
conventionally *checked* exceptions as if they were unchecked can only
appear sloppy from the point of view of other JVM languages calling
Clojure code.

IMHO Clojure should be throwing (extensions of) RuntimeException
unless it's just passing through an Exception originating form some
lower-level call into the JRE.

> 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

-- 
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