This is a follow up to an older question.
Given a ISBN number, e.g. 3-528-03851-5 which exception type should I raise if the passed in string doesn’t match the format X-XXX-XXXXX-X?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Raise a
ValueError.It’s pretty much the standard way of saying “you’ve given me a value that doesn’t make sense”. For example:
>>> int("a") Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: 'a' >>> import shlex; shlex.split("'") Traceback (most recent call last): ... ValueError: No closing quotationContrast this with a
TypeError, which is raised when a type is incorrect:>>> d = {} >>> d[{}] Traceback (most recent call last): File "", line 1, in TypeError: unhashable type: 'dict'