You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm developing an async desktop application with Flet 0.80.5 on Windows 10 (Python 3.13.1), and I'm stuck on handling exceptions triggered in the on_click event of Flet controls (e.g. ElevatedButton, TextButton).
Current Problem
When an unhandled exception occurs inside the async on_click callback function, the app directly pops up an exception traceback window. The only way to continue using the app is to close it and restart it, and the UI can't stay in its original state – this creates a very poor user experience.
What I've Tried (But All Failed)
Registered a global error handler with page.on_error – cannot catch exceptions from on_click callbacks at all.
Tried setting a custom asyncio exception handler to catch errors, which also had no effect on on_click exceptions:
importasynciodefexception_handler(loop, context):
# My custom exception handling logicpassloop=asyncio.get_running_loop()
loop.set_exception_handler(exception_handler)
My Questions
For Flet 0.80.5 in async mode on Win10, is there an official/recommended method to catch and handle exceptions in control event callbacks like on_click?
How can I handle the exception manually (e.g. show a friendly error message on the page) and keep the UI intact, instead of the app crashing with a traceback popup?
Env Info
Flet version: 0.80.5
OS: Windows 10
App type: Flet desktop application (async mode)
Python version: 3.13.1
Any solutions, code examples, or hints would be greatly appreciated! Thanks a lot for your help 😊
E:\data\Develop\test\test_flet>uv run main.py
Unhandled error in'on_click' handler
Traceback (most recent call last):
File "E:\data\Develop\test\test_flet\.venv\Lib\site-packages\flet\messaging\session.py", line 198, in dispatch_event
await control._trigger_event(event_name, event_data)
File "E:\data\Develop\test\test_flet\.venv\Lib\site-packages\flet\controls\base_control.py", line 318, in _trigger_event
await event_handler()
File "E:\data\Develop\test\test_flet\main.py", line 17, in start_counter
raise
RuntimeError: No active exception to reraise
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Question
Hi all,
I'm developing an async desktop application with Flet 0.80.5 on Windows 10 (Python 3.13.1), and I'm stuck on handling exceptions triggered in the
on_clickevent of Flet controls (e.g. ElevatedButton, TextButton).Current Problem
When an unhandled exception occurs inside the async
on_clickcallback function, the app directly pops up an exception traceback window. The only way to continue using the app is to close it and restart it, and the UI can't stay in its original state – this creates a very poor user experience.What I've Tried (But All Failed)
page.on_error– cannot catch exceptions fromon_clickcallbacks at all.on_clickexceptions:My Questions
on_click?Env Info
Any solutions, code examples, or hints would be greatly appreciated! Thanks a lot for your help 😊
Code sample
Error message
------------------------------------------------------
Beta Was this translation helpful? Give feedback.
All reactions