What type of exception does MicroPython raise when the stop button is pressed in Thonny?
Posted: Tue Mar 29, 2022 3:46 am
If I write a code that for example looks something like this:
The code inside except is executed if Thonny's stop button is pressed, but as you may know, placing an except without defining which exception to handle is not a good practice.
So I need to know exactly the exception to be able to reset the state of the pins and other external elements like displays, otherwise if a different exception occurs, I will not be able to know its cause.
I should also clarify that in Python, the code inside except is not executed if the stop button is pressed, it only happens in MicroPython.
Code: Select all
try:
while True:
time.sleep(1)
pass
except:
#Code that will be executed if the stop button is pressed in Thonny
with open('data.txt', 'w') as f:
f.write("Exception raised")
So I need to know exactly the exception to be able to reset the state of the pins and other external elements like displays, otherwise if a different exception occurs, I will not be able to know its cause.
I should also clarify that in Python, the code inside except is not executed if the stop button is pressed, it only happens in MicroPython.