:default catch blocks with core.async and clojurescript

135 views
Skip to first unread message

cameron

unread,
May 15, 2016, 12:31:00 AM5/15/16
to Clojure
I'm having an issue where :default catch blocks are not working in clojurescript when in a go block.

The following code prints "a str" as expected:

(prn (try
           (throw "a str")
           (catch :default e e )))

The same code in a go block results in an unhandled exception 
(go (prn (try
                (throw "a str")
                (catch :default e e ))))

I can see an old core.async issue that added support for :default (http://dev.clojure.org/jira/browse/ASYNC-42
but no other references, is this a regression or something I'm missing?

I'm using clojurescript  "1.8.51"  and core.async "0.2.374"

Cameron.

Kevin Downey

unread,
May 15, 2016, 9:39:32 PM5/15/16
to clo...@googlegroups.com
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@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+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to clojure+u...@googlegroups.com
> <mailto:clojure+u...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

You will likely find that (throw (js/String. "a str")) will work the
same in both.

This issue has two parts:

1. String literals are somehow not objects or something in javascript (I
don't entirely understand this, but I vaguely recall that it is a thing)

2. The go macro uses js/Object as the exception type in the "catch all"
exception handler it creates to emulate exception handling.

You can verify that the combination of these two things causes this
problem by playing with this code:

(try (throw "foo") (catch js/Object e :good))

(try (throw (js/String. "foo")) (catch js/Object e :good))

(try (throw "foo") (catch :default e :good))

The "Fix" for the issue you linked didn't change "js/Object" to
":default" in the catch all, so it didn't actually fix anything.

--
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

Kevin Downey

unread,
May 16, 2016, 5:18:26 PM5/16/16
to clo...@googlegroups.com
I am not entirely sure what to do with this. What I did was re-open
async-42 with a link to this thread
Reply all
Reply to author
Forward
0 new messages