On Sat, Jun 6, 2009 at 10:42 AM, Stephen C. Gilardi<squee...@mac.com> wrote:
> I've checked in changes to clojure.contrib.except to allow the functions it
> provides to produce exceptions that wrap other exceptions: they now support
> "causes".
>
> I believe it's now fully general and will be convenient to use for all of
> our exceptional needs.
>
> The attached text file contains a demo session at the repl showing some of
> its features.

This looks really easy to use, Stephen, thanks.

Since the time I put the rather more top-heavy error-kit in contrib,
it's become increasingly clear to me that hardly anybody (myself
included) need or use the continue-with and bind-continue features it
provides.

That leaves as its only used feature the ability to define and catch
custom error types that can be created without AOT compilation.  But
I'm starting to come around to what I think Rich has been pointing out
all along: that having singly-typed errors is not necessarily a great
idea.  Clojure multi-methods don't require objects to have a single
type after all -- you can dispatch on whatever you'd like.  Why should
exceptions be any different?

So here's an idea:  what if Clojure (or contrib for now) provided
a single new Exception type that besides the normal error string also
carried an object: probably a map with unspecified content (a bit like
metadata is now).  Then a lib like contrib.except could make it easy
to toss bits of detail into the exception that could be read easily
when caught.  This would allow the simplicity that contrib.except
provides now and would allow you to provide as much detail as an
error-kit error without even having to declare an error type.

Perhaps using it would look something like:

  (defn foo [x y]
    (if (neg? x)
      (throwf :source ::Args, :arg 'x, :value x,
              "The value x may not be negative")
      (+ x y)))

  (try
    (foo -5 10)
    (catch ClojureError e
      (if-not (isa? ::Args (:source e))
        (throw e)
        (printf "Argument was incorrect:" e))))

I suppose the catch clause could be augmented:

  (tryf
    (foo -5 10)
    (catchf [e] (isa? ::Args (:source e))
      (printf "Argument was incorrect:" e)))

...or something.

Any thoughts?
--Chouser

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