Handling RuntimeError Exceptions in Python