Python error handling and python error handling

Source: Internet
Author: User

Python error handling and python error handling

It is inconvenient to use the error code to indicate whether an error occurs. Because the normal results returned by the function itself are mixed with the error code, the caller must use a large amount of code to determine whether an error occurs:

Def foo (): r = some_function () if r = (-1): return (-1) # do something return rdef bar (): r = foo () if r = (-1): print 'error' else: pass

But that's what Go does. Haha!

In python, try… is still used... Else t .... Finally.

Try: print 'try... 'r = 10/0 print 'result: ', rexcept ZeroDivisionError, e: print 'couldn't:', efinally: print 'Finally... 'print 'end'

Articles you may be interested in:
  • Python exception handling instance details
  • Python exception handling Summary
  • Introduction to five exception handling mechanisms in python
  • Python error handling
  • Zero-Basic python crawler-based HTTP Exception Handling
  • Python standard exception and Exception Handling
  • How to handle socket remote connection errors in python
  • Python implements Remote File Reading with error handling
  • Tutorial on Exception Handling in Python Programming

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.