Fork me on GitHub
#re-frame
<
2021-02-05
>
Kevin13:02:37

Hey all. I have the following code:

(try
  [[]]
  (catch :default e
    [:div "Default content"]))
But this results in breaking the webpage with an Uncaught Error: Invalid arity: 0 error. Is there any way to catch this so teh the "default content" string is shown?

p-himik14:02:01

[[]] doesn't throw - you cannot use try/catch here. What throws is some Reagent/React machinery, waaaay down the line. You can try using React's error boundaries that are supported by Reagent.

manutter5114:02:31

You could also use [(throw (ex-msg "BOOM!"))] instead of [[]] if you’re just trying to exercise your try/catch. See also the js/window.onerror property.

Kevin14:02:15

I'll try the react error boundary, thanks!

Kevin14:02:10

Works like a charm, thanks!

👍 3