appendix exceptions what happens if the user entered at the prompt instead of an actual numeric valuepython raises an exception which causes the program to abort with the following message printed to the terminal traceback (most recent call last)file ""line in valueerrorinvalid literal for int(with base ' xsince python cannot convert the string " xto an integer valueit raises an exception instead of having the program abort due to the exceptionwe can provide code to detect and catch the exception and request that the user try again while truetryvalue intinput("enter an integer value"break except valueerror print"you must enter an integer value try again the try block flags the code in which we want to catch any exceptions that may be raised during execution the except block indicates the action to take when the given type of exception is raised within the corresponding try block if no exception is raisedexecution flows normally and the except block is skipped when an exception is raisedthe normal flow of execution is interrupted if an except block is provided for the type of exception raisedexecution jumps to the first statement within that except block on the other handif there is no corresponding except blockthe program terminates raising exceptions python automatically raises exceptions when an error occurs during program execution for various language constructs and library modules but you can also raise an exception when you detect an error in your code consider the following functionwhich accepts two arguments and returns the minimum of the twodef minarg arg )if arg is none or arg is none raise typeerror"arguments to min(cannot be noneif arg arg return arg else return arg if we define this function as accepting two comparable values other than none and return the minimum of the twowe need to make sure the arguments are valid that isneither argument is null if one or both of the arguments is nullthen we raise typeerror exception to flag an error using the raise statement consider the function cally minxnone