Summarize
- Exception occurred in try, execution except
- No exception occurs in try, execute else
- The exception in try prevents all subsequent actions of the try
- Return in try will prevent else from executing
- Any return will not prevent the execution of the finally
1 defExcept_no_return ():2 """3 exception occurred in try, execution except4 output: In try-in except-in finally-none5 : return:6 """7 Try:8 Print('In try')9A = 1/0Ten exceptZerodivisionerror: One Print('In except') A Else: - Print('In else') - finally: the #return to this - Print('In finally') - - + defElse_no_return (): - """ + no exception occurs in try, execute else A output: In try-in else-in finally-none at : return: - """ - Try: - Print('In try') - exceptZerodivisionerror: - Print('In except') in Else: - Print('In else') to finally: + #return to this - Print('In finally') the * $ deftry_except_finally ():Panax Notoginseng """ - the exception in try prevents all subsequent actions of the try the output: In try-in else-in Finally-return in finally + : return: A """ the Try: + Print('In try') -A = 1/0 $ return "return in Try" $ exceptZerodivisionerror: - Print('In except') - return "return in except" the Else: - Print('In else')Wuyi return "return in Else" the finally: - #return to this Wu Print('In finally') - return "return in finally" About $ - deftry_finally (): - """ - return in try will prevent else from executing A output: In try-in Finally-return in finally + : return: the """ - Try: $ Print('In try') the return "return in Try" the exceptZerodivisionerror: the Print('In except') the return "return in except" - Else: in Print('In else') the return "return in Else" the finally: About #return to this the Print('In finally') the return "return in finally" the + - deftry_else_finally (): the """Bayi any return will not prevent the execution of the finally the output: In try-in else-in Finally-return in finally the : return: - """ - Try: the Print('In try') the exceptZerodivisionerror: the Print('In except') the return "return in except" - Else: the Print('In else') the return "return in Else" the finally:94 #return to this the Print('In finally') the return "return in finally"
Python Exception handling