There is a rule in Python programming called “it is Easier to Ask for Forgiveness than for Permission” (in short: EAFP) 1.

It means that you should catch exceptions instead of checking values for validity.