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):
    time.sleep(0.2)
    try:
        raise ValueError("Error. No error Provided")
    except Exception as ex:
        error_panel.object = "```bash\n" + traceback.format_exc() + "\n```"

button.on_click(raise_error)
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):
        @functools.wraps(function)
        def wrapper(self, *args, **kwargs):
            try:
                return function(self, *args, **kwargs)
            except Exception as e:
                self.log_box.value = str(e)
        return wrapper

@try_decorator
def func()...
2 Likes