What is wrong with using a bare ‘except’? [duplicate]

Bare except will catch exceptions you almost certainly don’t want to catch, including KeyboardInterrupt (the user hitting Ctrl+C) and Python-raised errors like SystemExit

If you don’t have a specific exception you’re expecting, at least except Exception, which is the base type for all “Regular” exceptions.

That being said: you use except blocks to recover from known failure states. An unknown failure state is usually irrecoverable, and it is proper behavior to fatally exit in those states, which is what the Python interpreter does naturally with an uncaught exception.

Catch everything you know how to handle, and let the rest propagate up the call stack to see if something else can handle it. In this case the error you’re expecting (per the docs) is pyautogui.ImageNotFoundException

Leave a Comment