Send user warning messages on Python error

I’m wondering if there’s a built-in default method to send warning messages to the user when they do something wrong. For example, in my example, the user needs to load in a certain kind of file using the FileInput; if the file is formatted improperly, my Python code will throw an exception with the message “Improperly formatted file”. I want to catch this exception and display something to the user that says “Improperly formatted file”.

I saw bokeh.core.validation and bokeh.util.warning, but I’m not sure what exactly these do and whether they’re are meant for my use case. If I should be using them, I’m not so sure how I’d implement them. Would they go in the callback method called by FileInput.on_change()? How so?

Or do I need to build my own tool for this, e.g., put in an invisible Div at the top of the page that I send a callback to whenever I catch an error?

This is the best solution. The modules you mention are internal utilities for the library itself, and not useful for users.