Python

Get Age

Function that uses custom error checks if an input age value is in bounds

The program shows how to to raise errors, as well as how to create a custom error.

The program will ask for a age value. If the value is not a number it re-asks the question. If the age is out of a given bounds a error is raised. The custom error is created as a class with another related error class as an inheritance.

Example:

> python get_age.py

> How old are you? as1

> Invalid integer? input

> How old are you? 31

> 31

> How old are you? 133

> Traceback (most recent call last):

> File "get_age.py", line 72, in

> print get_age1()

> File "get_age.py", line 42, in get_age1

> raise OutOfRangeError("The value", age, "Is out of the range 0 to 122")

> __main__.OutOfRangeError: ('The value', '133', 'Is out of the range 0 to 122')