May-06-2018, 02:26 PM
(This post was last modified: May-06-2018, 02:26 PM by Gribouillis.)
(May-06-2018, 11:42 AM)Otbredbaron Wrote: Why do we need to be explicit and write except ValueError?I'm not sure I understand exactly what you mean, but here I know that if
i[1]
contains anything that is not convertible to an integer the call to int()
will raise ValueError. In such a case, I always catch the exact exception because I don't want to catch anything else. For example if for some reason there is no i[1]
, python will throw KeyError
and I don't want to catch this at this point. For debugging purposes, it is always better to let unexpected exceptions propagate.