Python Exception handling

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.