On Fri, Aug 28, 2009 at 16:57, John Harrop<[email protected]> wrote:
> On Fri, Aug 28, 2009 at 8:50 AM, Rich Hickey <[email protected]> wrote:
>>
>> On Thu, Aug 27, 2009 at 8:10 PM, Tim Snyder<[email protected]> wrote:
>> >
>> > Well, I can see that LazySeq does indeed catch and wrap all Exceptions
>> > in a RuntimeException.  I also think I can work around it, but I'd
>> > like to know why this was done?
>> >
>> > Was it necessary given the checked vs. unchecked exception system of
>> > Java?
>> >
>>
>> Yes.
>
> What about declaring IFn.invoke() as "throws Exception"? Or did you think
> that would make calling Clojure from Java too painful? Or was there some
> other reason?

Actually, you *can* throw checked exceptions on the jvm without
declaring that you throw them. Neither the runtime nor the byte code
verifying enforce the "you must declare checked exceptions as thrown"
rule. This rule is enforced only by javac, and that can be gotten
around as was demonstrated recently by Reinier Zwitserloot in a
javaposse thread about exception handling:

http://groups.google.com/group/javaposse/msg/039f6590afe99390?dmode=source

public class Sneak {
        public static RuntimeException
        sneakyThrow(Throwable t) {
                if ( t == null ) throw new NullPointerException("t");
                Sneak.<RuntimeException>sneakyThrow0(t);
                return null;
        }

        @SuppressWarnings("unchecked")
        private static <T extends Throwable> void
        sneakyThrow0(Throwable t) throws T {
                throw (T)t;
        }
}

Using something like this might be in extremely poor taste in Java,
but it I think it would fit right in for Clojure, which (thankfully)
doesn't distinguish between checked and unchecked exceptions.

// Ben

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to