Is there a way to redirect exceptions to frontend text box?

When I have:

Exception in callback functools.partial(<bound method IOLoop._discard_future_result

Is there a way to stream these exceptions to something like pn.pane.Markdown()?

Something could be built of the below

import panel as pn
import time
import traceback

error_panel = pn.pane.Markdown(height=200, width=800)
button = pn.widgets.Button(name="Run")

def raise_error(*events):
        raise ValueError("Error. No error Provided")
    except Exception as ex:
        error_panel.object = "```bash\n" + traceback.format_exc() + "\n```"

pn.Column(error_panel, button).servable()

Thanks for the quick reply!

I was wondering if there was a more general way rather than putting try/except in every function?

I don’t think so. But eventually there should be some mechanism. Maybe an idea for a Feature Request?

1 Like

Thanks. I’ve decided to use decorators to wrap try/except.

    def try_decorator(function):
        def wrapper(self, *args, **kwargs):
                return function(self, *args, **kwargs)
            except Exception as e:
                self.log_box.value = str(e)
        return wrapper

def func()...