Use of Python exceptions

Source: Internet
Author: User

Pseudo code:

Try

The code of the error section ...

Except Exception as E:

print ' 404 Web page ' #Exception是所有错误类型的父类, including all error messages

Finally

Action (whether or not an error occurs, finally is executed)

defFoo (s):return10/Int (s)defBar (s):returnFoo (s) * 2defMain ():Try: Bar ('0')    exceptException as E:Print('Error:', E)finally:        Print('finally ...')

Custom Thrown exception: (less used) http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/ 00143191375461417a222c54b7e4d65b258f491c093a515000

# err_raise.py class Fooerror (valueerror):     Pass def Foo (s):     = Int (s)    if n==0:        raise fooerror ('Invalid Value:%s' % s)    return / nfoo ('0 ')

Use of Python exceptions

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.