title: better way of handle clojure exceptions and why my exception is not captured inside go block
body: <p>I'm trying to found a better way of handle exceptions in clojure, I'm using <a href="https://github.com/alaisi/postgres.async" rel="nofollow">https://github.com/alaisi/postgres.async</a> which thrown an exeption when fail, but I would prefer return false (because I'm using a validator) or even better something like a Either monad (or something more simple like this <a href="http://adambard.com/blog/acceptable-error-handling-in-clojure/" rel="nofollow">http://adambard.com/blog/acceptable-error-handling-in-clojure/</a> )</p>
  
  <p>1) I'm trying to catch the exception and if exist return false, but the code doesnt works (doesnt return false and thrown the exception).</p>
  
  <pre><code>(try
        (dosql [tx (&lt;begin! db)
                   ucount (&lt;execute! tx ["UPDATE groups SET garticlescounter=garticlescounter + 1 WHERE gid=$1"
                                         groupid])
                   uartc (&lt;execute! tx ["UPDATE subtopics SET starticlescount=starticlescount + 1 WHERE stid=$1"
                                        sid])
                   uartins (&lt;insert! tx
                                     {:table "articles"}
                                     {:aurl url :atitle title :asuttopicid sid :acommentcount 0 :alikescount 0 :auid uid})
                   ok? (&lt;commit! tx)]
                  ok?)
        (catch Exception _ false))
  </code></pre>
  
  <p>2)would be possible wrap in a way where if works return ok?  and if doesnt works return false, or maybe [ok? nil] and [nil error] maybe a macro?</p>
  
  <p>----thanks to swinn I did this</p>
  
  <pre><code>;must receive an optional parameter for error response or 
  ; build a [nil ok] response but just know this works for me...
  (defmacro async-try-block! [block]
    `(let [chn# (!/chan 1)]
       (!/go
         (let [response# (try
                          ~block
                          (catch Throwable e#))]
           (if (instance? Throwable response#) (!/put! chn# false) (!/put! chn# response#))))
       chn#))
  
  (async-try-block!
      (dosql [tx (&lt;begin! db)
              ucount (&lt;execute! tx ["UPDATE groups SET garticlescounter=garticlescounter + 1 WHERE gid=$1"
                                    groupid])
              uartc (&lt;execute! tx ["UPDATE subtopics SET starticlescount=starticlescount + 1 WHERE stid=$1"
                                   sid])
              uartins (&lt;insert! tx
                                {:table "articles"}
                                {:aurl url :atitle title :asuttopicid sid :acommentcount 0 :alikescount 0 :auid uid})
              ok? (&lt;commit! tx)]
             ok?))
  </code></pre>