alsopay attention to the output when no exception is raisedboth the else and the finally clauses are executed the else clause may seem redundantas the code that should be executed only when no exception is raised could just be placed after the entire try except block the difference is that the else block will still be executed if an exception is caught and handled we'll see more on this when we discuss using exceptions as flow control later any of the exceptelseand finally clauses can be omitted after try block (although else by itself is invalidif you include more than onethe except clauses must come firstthen the else clausewith the finally clause at the end the order of the except clauses normally goes from most specific to most generic the exception hierarchy we've already seen several of the most common built-in exceptionsand you'll probably encounter the rest over the course of your regular python development as we noticed earliermost exceptions are subclasses of the exception class but this is not true of all exceptions exception itself actually inherits from class called baseexception in factall exceptions must extend the baseexception class or one of its subclasses there are two key exceptionssystemexit and keyboardinterruptthat derive directly from baseexception instead of exception the systemexit exception is raised whenever the program exits naturallytypically because we called the sys exit function somewhere in our code (for examplewhen the user selected an exit menu itemclicked the "closebutton on windowor entered command to shut down serverthe exception is designed to allow us to clean up code before the program ultimately exitsso we generally don' need to handle it explicitly (because cleanup code happens inside finally clauseif we do handle itwe would normally reraise the exceptionsince catching it would stop the program from exiting there areof coursesituations where we might want to stop the program exitingfor exampleif there are unsaved changes and we want to prompt the user if they really want to exit usuallyif we handle systemexit at allit' because we want to do something special with itor are anticipating it directly we especially don' want it to be accidentally caught in generic clauses that catch all normal exceptions this is why it derives directly from baseexception the keyboardinterrupt exception is common in command-line programs it is thrown when the user explicitly interrupts program execution with an os-dependent key combination (normallyctrl cthis is standard way for the user to deliberately interrupt running programand like systemexitit should almost always respond by terminating the program alsolike systemexitit should handle any cleanup tasks inside finally blocks