Skip to main content
Source Link
Constantinius
  • 35.2k
  • 9
  • 79
  • 85

You can catch all exceptions with the simple except: statement. But this is considered dangerous, since this also covers syntactical errors.

The best practice is to cover all possible and expected exception types with one except clause. Consider the following example:

except (IOError, ArgumentError), e:
    print(e)

This example catches the two expected exceptions, all others will fall through and will be written to stderr.