2024 Clojure 状况调查!中分享你的想法。

欢迎!请查看关于页面以了解更多关于此处如何工作的信息。

0
core.async

ClojureScript 中,如果在“go”块中的“try”块抛出一个字符串,那么“finally”会被忽略。

示例代码

(ns demo
(:require-macros
(link: cljs.core.async.macros :refer [go]))

;; 输出: "in a finally"
(go (try (throw (ex-info "THROWN" nil)) (finally (println "in a finally"))))

;; 输出: "in a finally"
(go (try (throw (js/Exception. "THROWN")) (finally (println "in a finally"))))

;; 输出: "in a finally"
(go (try (throw (#js {})) (finally (println "in a finally"))))

;; 输出: "in a finally"
(try (throw "THROWN") (finally (println "in a finally")))

;; 输出: nothing
(go (try (throw "THROWN") (finally (println "in a finally"))))

5 答案

0

评论来自:hubert

也失败于
org.clojure/clojure "1.8.0"
org.clojure/clojurescript "1.9.671"
org.clojure/core.async "0.3.443"

0

评论来自:hiredman

这个问题可能出现在https://github.com/clojure/core.async/blob/17112aca9b07ebba6ce760ca01d117c24c80cc9a/src/main/clojure/cljs/core/async/impl/ioc_macros.clj#L861

如果那样的话,当你用 js/Object 无法捕获任何东西的时候(我知道字符串和数字就是这样的情况,不确定还有哪些),你会看到这种行为。不是 finally 被跳过,而是 go 块状态机完全未能处理被抛出的东西并完全崩溃。

0

评论来自:hubert

抱歉出现错别字。正确的标题应该是:
(CLJS) "go"块中的"try"语句中的"finally"部分,如果抛出字符串,则会跳过。

0

评论来自:hiredman

https://dev.clojure.org/jira/browse/ASYNC-184 上的补丁通过将宏展开中的 (catch js/Object ...) 替换为 (catch :default ...) 来解决这个问题。

0
参考:https://clojure.atlassian.net/browse/ASYNC-200 (由 alex+import 报告)
...