in this exampleif filename txt does not existan input/output exception called ioerror is generated on the other handif the file does existthere may be certain things that we want to do with it we can put those in the else block try/finally and with/as there is one more block you can use called finally things in the finally block are things that must be executed whether or not an exception occurs so even if an exception occurs and your program crashesthe statements in the finally block will be executed one such thing is closing file if you just put the file closing after the try block and not in the finally blockthe program would crash before getting to close the file open'filename txt '' ' 'hi trysome code that could potentially fail goes here finallyf close(the finally block can be used along with except and else blocks this sort of thing with files is common enough that it is has its own syntaxs 'hi with open'filename txt 'as fprint(sfile=fthis is an example of something called context manager context managers and try/finally are mostly used in more complicated applicationslike network programming more with exceptions there is lot more that can be done with exceptions see the python documentation [ for all the different types of exceptions in factnot all exceptions come from errors there is even statement called raise that you can use to raise your own exceptions this is useful if you are writing your own classes to be used in other programs and you want to send messageslike error messagesto people who are using your class