My following code was designed to handle exceptions and switch serialport if nothing was found
try:
serial_port = '/dev/cu.usbserial-10'
except:
try:
serial_port = '/dev/cu.usbserial-110'
except:
print("Unable to find sensor. Try again")
However it is not actually handling exceptions and still lets them get through to the console:
Traceback (most recent call last):
File "/Users/username/Library/Python/3.10/lib/python/site-packages/serial/serialposix.py", line 322, in open
self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
FileNotFoundError: [Errno 2] No such file or directory: '/dev/cu.usbserial-10'
I have set it in the code so that if there is no /dev/cu.usbserial-10
it tries serial-110
and if thats not there, it prints something, but it does not print ever.