if we run this example--which illustrates almost every conceivable exception handling scenario-- few timeswe'll get different output each timedepending on which exception random chooses here are some example runspython finally_and_else py raising none this code called if there is no exception this cleanup code is always called python finally_and_else py raising caught typeerror this cleanup code is always called python finally_and_else py raising caught some other errorindexerror this cleanup code is always called python finally_and_else py raising caught valueerror this cleanup code is always called note how the print statement in the finally clause is executed no matter what happens this is extremely useful when we need to perform certain tasks after our code has finished running (even if an exception has occurredsome common examples includecleaning up an open database connection closing an open file sending closing handshake over the network the finally clause is also very important when we execute return statement from inside try clause the finally handle will still be executed before the value is returned