Yup. Python allows you to catch exceptions using exception handlers.
Code:
try:
... camera initialization code goes here
except:
self.logger.error("No camera detected")
Or if you want it to crash when you're not at a match -- but not during a match, you can do this instead:
Code:
try:
...
except:
if not self.isFmsAttached():
raise
We should probably add a note about this to the documentation, or make sure it doesn't crash.
Similar issues exist if you don't test your code well enough, and it crashes somewhere -- you're done for even on simple syntax errors. For that reason, I've thought about creating a version of iterative robot that would only crash if the robot wasn't connected to the FMS. See
https://github.com/robotpy/robotpy-wpilib/issues/96 for my thoughts.