Is there any way to catch exceptions raised during rendering?
When an exception is raised during rendering, Solara displays its traceback as a plain text instead of a page layout. Is it possible to catch such exception and show its traceback in a component on a page? Something like React error boundary would be really helpful here.
5 Replies
Good question, and there is an example at https://solara.dev/documentation/api/hooks/use_exception but that is broken (we'll need to look into that).
I have a working example here, with a comment about a bug in reacton, I hope this helps you: https://app.py.cafe/snippet/solara/v1?projectId=htcps_fmjs
PyCafe - Solara - Exception Handler Using Solara
PyCafe: get your daily fix of Python!
Thank you! I experimented with that a bit and it seems that function components are working too:
https://app.py.cafe/snippet/solara/v1?projectId=iqmfu9u0mom
PyCafe - Solara - Exception Handler Using Solara
PyCafe: get your daily fix of Python!
Nice, did you find a pattern in it? When it works and when it does not?
It is strange, but replacing
solara.VBox()
with rv.Html(tag="div")
fixes the use_exception example