在ClojureScript中,如果在“go”块中的“try”中抛出字符串,则“finally”会被忽略。
示例代码
(ns demo
(:require-macros
(link: cljs.core.async.macros :refer [go]))
;; 打印: "在finally中"
(go (try (throw (ex-info "THROWN" nil)) (finally (println "在finally中"))))
;; 打印: "在finally中"
(go (try (throw (js/Exception. "THROWN")) (finally (println "在finally中"))))
;; 打印: "在finally中"
(go (try (throw (#js {})) (finally (println "在finally中"))))
;; 打印: "在finally中"
(try (throw "THROWN") (finally (println "在finally中")))
;; 打印: 无
(go (try (throw "THROWN") (finally (println "在finally中"))))