gpt4 book ai didi

error-handling - Clojurescript/试剂处理错误

转载 作者:行者123 更新时间:2023-12-03 07:59:15 24 4
gpt4 key购买 nike

我们开始在产品的下一个开发阶段中使用Clojuescript/Reagent。基本上,我们需要一种方法来对原子执行单个操作,然后我们想到了一种方法:
(def应用程序状态(r/atom {}))

(defn select [index]
(swap! app-state
#(-> %
(assoc-in [:storyboard :pages 0 :layers 0 :children 0 :is_selected] true)
(assoc-in (GET ....)) ;; ajax call
(assoc-in [:selected :selected_tab] "tab_properties")
(assoc-in [:selected :page_object_cursor] [0])
)))

基本上,交换具有将所有需要的操作链接在一起的功能。太好了但是,我正在寻找处理错误的方法。我想为错误提供一个单独的原子:
(def errors (r/atom []))

并在发生错误时捕获它并将其添加到错误中,而无需交换应用程序状态(应用程序保持在最后的稳定状态)。因此,我们使用链条上的 throw 和尝试仙人掌
(defn change-title [title]
(try
(swap! app-state
#(-> %
(assoc :text title)
((fn [state]
(throw "there is an error")))
))
(catch js/Object e
(swap! errors conj e))))

所以我希望错误会被捕获,而@errors会得到它。但是现实是:

*未捕获到错误

weather_app $ core $ change_title @ core.cljs?rel = 1450266738018:59(匿名函数)@ core.cljs?rel = 1450266738018:108executeDispatch @ react-with-addons.inc.js:3311SimpleEventPlugin.executeDispatch @ react-with-addons。 inc.js:17428forEachEventDispatch @ react-with-addons.inc.js:3299executeDispatchesInOrder @ react-with-addons.inc.js:3320executeDispatchesAndRelease @ react-with-addons.inc.js:2693forEachAccumulated @ react-with-addons.inc。 js:19430EventPluginHub.processEventQueue @ react-with-addons.inc.js:2900runEventQueueInBatch @ react-with-addons.inc.js:11217ReactEventEmitterMixin.handleTopLevel @ react-with-addons.inc.js:11243handleTopLevelImpl @ react-with-addons。 inc.js:11329Mixin.perform @ react-with-addons.inc.js:18402ReactDefaultBatchingStrategy.batchedUpdates @ react-with-addons.inc.js:9669batchedUpdates @ react-with-addons.inc.js:16633ReactEventListener.dispatchEvent @ react- with-addons.inc.js:11423 *

最佳答案

(catch :default e
(swap! errors conj e))))

因为抛出的字符串不是对象,而是字符串!

关于error-handling - Clojurescript/试剂处理错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34312417/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com