Hi all

I am trying to figure out some systematic and clear way how to handle exceptions in clojure and their bubbling up through the call chain. Let me illustrate it on some code examples (not executable, just to show the principle).

(defn get-from-io [p]
     (access-external-source p))

(defn process-io [p]
    (let [response (get-from-io p)
             code (.getresponsecode response)
             message (.getmessage response)]
        (if (= code 0)
             do something....)
        message))

(defn process-data [d]
    "process data, expecting something parsable"
    (let [p (parse d)]
        function p
        function p
        p))

(defn run [u]
    (process-data (process-io u)))


Now, imagine the chain of calling functions is relatively big. Here it can all fall down on access-external-source causing an exception, but further up, maybe the message is scrambled, or pretty much anything.

The question is, wrapping all function in try - catch does not make is clearer (from a processing point of view). Returning nil from broken functions just adds a boilerplate code all the way up.

I could not find any guidelines of systematic approach of using "pure" functions in the mess of realworld.


Thanks in advance
Lukas

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