user input and error handling howeverwe only handle one of the potential errorsand using if-tests to test for every possible error can lead to quite complex programs insteadit is common in python and many other languages to try to do what we intend to andif it failsto recover from the error this principle uses the try-except blockwhich has the following general structuretryexceptif something goes wrong in the try blockpython will raise an exception and the execution jumps to the except block inside the except blockwe need to add our own code for catching the exceptionbasically to detect what went wrong and try to fix it if no errors occur inside the try blockthe code inside the except block is not run and the program simply moves on to the first line after the try-except block improving the atmospheric pressure program with try-except to apply the try-except idea to the air pressure programwe can try to read from the command line and convert it to floatandif this failswe tell the user what went wrong and stop the programimport sys tryh float(sys argv[ ]exceptprint('you failed to provide command line arg !'exit( print( exp(- / )one could argue that this is not very different from the program using the if-testbut we shall see that the try-except block has some benefits firstwe can try to run this program with different inputwhich immediately reveals problemterminal terminalpython altitude_cml_except py you failed to provide command line arg terminalpython altitude_cml_except py you failed to provide command line arg regardless of what goes wrong inside our try blockpython will raise an exception that needs to be handled by the except block the problem with our code is that all possible errors will be handled the same way in the first casethe problem is that there are no argumentsthat issys argv[ does not existwhich leads to an indexerror this situation is correctly handled