Switching to the appropriate Python exception type.