This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-09-10
Channels
- # announcements (8)
- # aws-lambda (4)
- # babashka (60)
- # beginners (65)
- # braveandtrue (5)
- # chlorine-clover (3)
- # cider (10)
- # clj-kondo (2)
- # cljdoc (2)
- # cljfx (32)
- # cljsrn (5)
- # clojure (198)
- # clojure-berlin (10)
- # clojure-europe (22)
- # clojure-france (1)
- # clojure-losangeles (33)
- # clojure-nl (3)
- # clojure-norway (22)
- # clojure-uk (35)
- # clojurescript (12)
- # code-reviews (14)
- # core-typed (1)
- # cursive (56)
- # datomic (13)
- # depstar (7)
- # emacs (1)
- # events (1)
- # figwheel-main (3)
- # fulcro (30)
- # graphql (15)
- # helix (1)
- # jobs (5)
- # juxt (6)
- # kaocha (14)
- # klipse (2)
- # malli (12)
- # off-topic (88)
- # portal (4)
- # re-frame (3)
- # reagent (5)
- # shadow-cljs (6)
- # specter (6)
- # sql (73)
- # tools-deps (15)
- # windows (4)
A little question
This is my renderer
(def renderer
(fx/create-renderer
:middleware (fx/wrap-map-desc #(root-view %))
:opts {:fx.opt/map-event-handler
(fn [x]
(try
(handle x)
(catch Exception e
{"want to show alert with exception info here"})))}))
And thank you @vlaaad for such a nice lib.
But the code above doesn't work as expected. When exception happends catch block not evaluated at all.
how do you know it’s not evaluated? have you tried putting println
in the catch block?
I did tried
Nope. Linear.
I will send a full code to try a little later. Sorry, I have to go now
At least I know I've got the idea right
(ns example.gui
(:require [cljfx.api :as fx]
[clojure.string :as str]))
(def *state
(atom 0))
(defmulti handle ::event)
(defmethod handle ::press
[_]
(throw
(Exception. "error")))
(defn root-view
[a]
{:fx/type :stage
:title "App"
:showing true
:width 800
:height 600
:scene
{:fx/type :scene
:root
{:fx/type :v-box
:alignment :center
:spacing 15
:children
[{:fx/type :h-box
:alignment :center
:spacing 15
:children
[{:fx/type :button
:text "Button"
:on-action {::event ::press}}]}]}}})
(def renderer
(fx/create-renderer
:middleware (fx/wrap-map-desc #(root-view %))
:opts {:fx.opt/map-event-handler
(fn [x]
(try
(handle x)
(catch Exception e
(print "sas"))))}))
(fx/mount-renderer *state renderer)
Try this @vlaaad
still nothing 😞
have you called (fx/mount-renderer *state renderer)
again after redefining renderer to use println
instead of print
?
Oh. I'm running it in calva repl... I guess that's the problem
I'm really sorrt.
sorry. It's the repl situation
I don’t know how calva output works, but I would guess that it can show only what was printed in the main thread, while JavaFX event handling happens on the JavaFX UI thread, so output probably goes to your process output pane
I figured that out. Thanks
I slightly edited your code so it shows a dialog:
(ns cljfx-ex
(:require [cljfx.api :as fx]
[clojure.main :as m]
[clojure.pprint :as pp]))
(def *state
(atom 0))
(defmulti handle ::event)
(defmethod handle ::press [_] (throw (Exception. "error")))
(defn root-view
[a]
{:fx/type :stage
:title "App"
:showing true
:width 800
:height 600
:scene {:fx/type :scene
:root {:fx/type :v-box
:alignment :center
:spacing 15
:children [{:fx/type :h-box
:alignment :center
:spacing 15
:children [{:fx/type :button
:text "Button"
:on-action {::event ::press}}]}]}}})
(def renderer
(fx/create-renderer
:middleware (fx/wrap-map-desc #(root-view %))
:opts {:fx.opt/map-event-handler
(fn [x]
(try
(handle x)
(catch Exception e
(fx/create-component
{:fx/type :dialog
:showing true
:dialog-pane {:fx/type :dialog-pane
:header-text "Event handling exception"
:content-text (-> e Throwable->map m/ex-triage m/ex-str)
:expandable-content {:fx/type :label
:text (with-out-str (pp/pprint e))}
:button-types [:ok]}}))))}))
(fx/mount-renderer *state renderer)
Yep. Thanks.