the last line of the error message indicates what happened exceptions come in different typesand the type is printed as part of the messagethe types in the example are zerodivisionerrornameerror and typeerror the string printed as the exception type is the name of the built-in exception that occurred this is true for all built-in exceptionsbut need not be true for user-defined exceptions (although it is useful conventionstandard exception names are built-in identifiers (not reserved keywordsthe rest of the line provides detail based on the type of exception and what caused it the preceding part of the error message shows the context where the exception happenedin the form of stack traceback in general it contains stack traceback listing source lineshoweverit will not display lines read from standard input bltin-exceptions lists the built-in exceptions and their meanings handling exceptions it is possible to write programs that handle selected exceptions look at the following examplewhich asks the user for input until valid integer has been enteredbut allows the user to interrupt the program (using control- or whatever the operating system supports)note that user-generated interruption is signalled by raising the keyboardinterrupt exception while truetryx int(input("please enter number")break except valueerrorprint("oopsthat was no valid number try again "the try statement works as follows firstthe try clause (the statement(sbetween the try and except keywordsis executed if no exception occursthe except clause is skipped and execution of the try statement is finished if an exception occurs during execution of the try clausethe rest of the clause is skipped then if its type matches the exception named after the except keywordthe except clause is executedand then execution continues after the try statement if an exception occurs which does not match the exception named in the except clauseit is passed on to outer try statementsif no handler is foundit is an unhandled exception and execution stops with message as shown above try statement may have more than one except clauseto specify handlers for different exceptions at most one handler will be executed handlers only handle exceptions that occur in the corresponding try clausenot in other handlers of the same try statement an except clause may name multiple exceptions as parenthesized tuplefor exampleexcept (runtimeerrortypeerrornameerror)pass class in an except clause is compatible with an exception if it is the same class or base class thereof (but not the other way around -an except clause listing derived class is not compatible with base classfor examplethe following code will print bcd in that orderclass (exception)pass (continues on next page errors and exceptions