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?[[]]
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.
https://github.com/reagent-project/reagent/blob/master/doc/ReactFeatures.md#error-boundaries
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.
I'll try the react error boundary, thanks!
Works like a charm, thanks!