Python Learning Notes (eight)-error, Debug, test

Source: Internet
Author: User

I. Error handling

1. Use try: Exception. Finally

Try:    print ' Try ... '    r = 10/0    print ' Result: ', R       # exception does not print this sentence except Zerodivisionerror, E: # If there is an exception, it will be captured to the C6/>print ' except: ', Eelse:    print ' No error! ' # If no exception is executed elsefinally:    print ' finally ... ' # finally is sure to execute the print ' END '
2. Log errors:

Using Logging.exception (E)


3. Throw an exception:

Raise Xxerror (XXX)

You can also write a raise directly, which throws the current error as it is.

Two. Commissioning

Bb

Three. Unit Testing

Cc

Four. Document testing

Dd

Python Learning Notes (eight)-error, Debug, test

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.