(continued from previous pageclass ( )pass class ( )pass for cls in [bcd]tryraise cls(except dprint(" "except cprint(" "except bprint(" "note that if the except clauses were reversed (with except first)it would have printed bbb -the first matching except clause is triggered the last except clause may omit the exception name( )to serve as wildcard use this with extreme cautionsince it is easy to mask real programming error in this wayit can also be used to print an error message and then re-raise the exception (allowing caller to handle the exception as well)import sys tryf open('myfile txt' readline( int( strip()except oserror as errprint("os error{ }format(err)except valueerrorprint("could not convert data to an integer "exceptprint("unexpected error:"sys exc_info()[ ]raise the try except statement has an optional else clausewhichwhen presentmust follow all except clauses it is useful for code that must be executed if the try clause does not raise an exception for examplefor arg in sys argv[ :]tryf open(arg' 'except oserrorprint('cannot open'argelseprint(arg'has'len( readlines())'lines' close(the use of the else clause is better than adding additional code to the try clause because it avoids accidentally catching an exception that wasn' raised by the code being protected by the try except statement when an exception occursit may have an associated valuealso known as the exception' argument the presence and type of the argument depend on the exception type the except clause may specify variable after the exception name the variable is bound to an exception instance with the arguments stored in instance args for conveniencethe exception instance defines __str__(so the arguments can be printed directly without having to reference args one may also handling exceptions