Skip to content

Commit 25953d6

Browse files
committed
Improve error handling, let user restart by touch after error
1 parent f96841c commit 25953d6

File tree

1 file changed

+8
-2
lines changed
  • CircuitPython_Zorque_Text_Game_openai

1 file changed

+8
-2
lines changed

CircuitPython_Zorque_Text_Game_openai/code.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# SPDX-FileCopyrightText: 2023 Jeff Epler for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33
import os
4+
import traceback
45

56
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
67
import adafruit_requests as requests
78
import adafruit_touchscreen
89
import board
910
import displayio
11+
import supervisor
1012
import terminalio
1113
from adafruit_esp32spi import adafruit_esp32spi
1214
from digitalio import DigitalInOut
@@ -254,5 +256,9 @@ def run_game_step(forced_choice=None):
254256
run_game_step("New game")
255257
while True:
256258
run_game_step()
257-
except (EOFError, KeyboardInterrupt) as e:
258-
raise SystemExit from e
259+
except Exception as e: # pylint: disable=broad-except
260+
traceback.print_exception(e)
261+
terminal.write(f"{clear}An error occurred (more details on REPL).\r\nTouch the screen to re-load")
262+
board.DISPLAY.refresh()
263+
get_touchscreen_choice()
264+
supervisor.reload()

0 commit comments

Comments
 (0)