class evenonly(list)def append(selfinteger)if not isinstance(integerint)raise typeerror("only integers can be added"if integer raise valueerror("only even numbers can be added"super(append(integerthis class extends the list built-inas we discussed in objects in pythonand overrides the append method to check two conditions that ensure the item is an even integer we first check if the input is an instance of the int typeand then use the modulus operator to ensure it is divisible by two if either of the two conditions is not metthe raise keyword causes an exception to occur the raise keyword is simply followed by the object being raised as an exception in the preceding exampletwo objects are newly constructed from the built-in classes typeerror and valueerror the raised object could just as easily be an instance of new exception class we create ourselves (we'll see how shortly)an exception that was defined elsewhereor even an exception object that has been previously raised and handled if we test this class in the python interpreterwe can see that it is outputting useful error information when exceptions occurjust as beforee evenonly( append(" string"traceback (most recent call last)file ""line in file "even_integers py"line in add raise typeerror("only integers can be added"typeerroronly integers can be added append( traceback (most recent call last)file ""line in file "even_integers py"line in add raise valueerror("only even numbers can be added"valueerroronly even numbers can be added append(