Ask Your Question

Revision history [back]

If you know the kind of errors that are raised by the wrong input (for example AttributeError and ValueError, a complete list of exceptions can be found in the docs of python), you can catch those errors and return or print an error message.

try:
    result = f.taylor(x,0,n)
except (AttributeError, ValueError):
   print('illegal input')
else:
   print(f, " = ", result)

Of course, catching the error and just printing illegal input may also hide the real problem to the user, so it may get harder to fix. You may read the section on errors from Python docs for more details.

If you know the kind of errors that are raised by the wrong input (for example AttributeError and ValueError, a complete list of exceptions can be found in the docs of python), you can catch those errors and return or print an error message.

try:
    result = f.taylor(x,0,n)
except (AttributeError, ValueError):
   print('illegal input')
else:
   print(f, " = ", result)

Of course, catching the error and just printing illegal input may also hide the real problem to the user, so it may get harder to fix. You may read the section on errorshow to handle exceptions from Python docs for more details.