Skip to content

Commit c62b30b

Browse files
Improve robustness by catching unhandled app exceptions
1 parent 99722fc commit c62b30b

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Simplify: don't rate-limit update_ui_threadsafe_if_foreground
55
- WiFi app: check "hidden" in EditNetwork
66
- Wifi app: add support for scanning wifi QR codes to "Add Network"
7+
- Improve robustness by catching unhandled app exceptions
78

89
0.5.2
910
=====

internal_filesystem/lib/mpos/activity_navigator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ def _launch_activity(intent, result_callback=None):
5050
activity._result_callback = result_callback # Pass callback to activity
5151
start_time = utime.ticks_ms()
5252
mpos.ui.save_and_clear_current_focusgroup()
53-
activity.onCreate()
53+
try:
54+
activity.onCreate()
55+
except Exception as e:
56+
print(f"activity.onCreate caught exception: {e}")
5457
end_time = utime.ticks_diff(utime.ticks_ms(), start_time)
5558
print(f"apps.py _launch_activity: activity.onCreate took {end_time}ms")
5659
return activity

internal_filesystem/lib/mpos/ui/view.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,31 @@ def setContentView(new_activity, new_screen):
99
global screen_stack
1010
if screen_stack:
1111
current_activity, current_screen, current_focusgroup, _ = screen_stack[-1]
12-
current_activity.onPause(current_screen)
13-
current_activity.onStop(current_screen)
12+
try:
13+
current_activity.onPause(current_screen)
14+
except Exception as e:
15+
print(f"onPause caught exception: {e}")
16+
try:
17+
current_activity.onStop(current_screen)
18+
except Exception as e:
19+
print(f"onStop caught exception: {e}")
1420

1521
from .util import close_top_layer_msgboxes
1622
close_top_layer_msgboxes()
1723

1824
screen_stack.append((new_activity, new_screen, lv.group_create(), None))
1925

2026
if new_activity:
21-
new_activity.onStart(new_screen)
27+
try:
28+
new_activity.onStart(new_screen)
29+
except Exception as e:
30+
print(f"onStart caught exception: {e}")
2231
lv.screen_load_anim(new_screen, lv.SCR_LOAD_ANIM.OVER_LEFT, 500, 0, False)
2332
if new_activity:
24-
new_activity.onResume(new_screen)
33+
try:
34+
new_activity.onResume(new_screen)
35+
except Exception as e:
36+
print(f"onResume caught exception: {e}")
2537

2638
def remove_and_stop_all_activities():
2739
global screen_stack
@@ -31,9 +43,18 @@ def remove_and_stop_all_activities():
3143
def remove_and_stop_current_activity():
3244
current_activity, current_screen, current_focusgroup, _ = screen_stack.pop()
3345
if current_activity:
34-
current_activity.onPause(current_screen)
35-
current_activity.onStop(current_screen)
36-
current_activity.onDestroy(current_screen)
46+
try:
47+
current_activity.onPause(current_screen)
48+
except Exception as e:
49+
print(f"onPause caught exception: {e}")
50+
try:
51+
current_activity.onStop(current_screen)
52+
except Exception as e:
53+
print(f"onStop caught exception: {e}")
54+
try:
55+
current_activity.onDestroy(current_screen)
56+
except Exception as e:
57+
print(f"onDestroy caught exception: {e}")
3758
if current_screen:
3859
current_screen.clean()
3960

0 commit comments

Comments
 (0)