Since a go block is async you cannot try/catch from outside. You need to either 
try/catch inside the block and return the exception as the result of the go 
block or use an extra channel to handle errors.

(def errors (async/chan))

;; exception handler
(go (loop []
      (when-let [ex (<! errors)]
        (do-something-with-ex ex)
        (recur))))

;; normal go
(go (loop []
      (try
        (something-that-might-throw)
        (catch :default e
          (>! errors e)))
      (recur)))

HTH,
/thomas

On Sunday, August 24, 2014 9:30:23 AM UTC+2, Yehonathan Sharvit wrote:
> I would like to catch exceptions that occur inside a go block. I need to 
> catch the exceptions from outside the go block.
> 
> I tried to write this piece of code but it didn't work. The exception was not 
> caught.
> 
> (try
>   (go 
>    (throw (js/Error."My Exception in go block")))
>   (catch js/Object e
>     (println "exception caught: " e)))
> 
> 
> Any idea?

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to