Reflex Cloud - Fast, secure & scalable hosting. One command to deploy.

Exception handlers

Added in v0.5.7

Exceptions handlers are functions that can be assigned to your app to handle exceptions that occur during the application runtime. They are useful for customizing the response when an error occurs, logging errors, and performing cleanup tasks.

Types

Reflex support two type of exception handlers frontend_exception_handler and backend_exception_handler.

They are used to handle exceptions that occur in the frontend and backend respectively.

The frontend errors are coming from the JavaScript side of the application, while backend errors are coming from the the event handlers on the Python side.

Register an Exception Handler

To register an exception handler, assign it to app.frontend_exception_handler or app.backend_exception_handler to assign a function that will handle the exception.

The expected signature for an error handler is def handler(exception: Exception).

Only named functions are supported as exception handler.

Examples