在 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")))
;; 打印: 什么都没有
(go (try (throw "THROWN") (finally (println "in a finally"))))