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"))))