Python exception handling-raise function usage, python-raise

Source: Internet
Author: User
Tags finally block

Python exception handling-raise function usage, python-raise

The raise statement manually raises an exception:

1 "raise" [expression ["," expression ["," expression]

 

 

In Python, to cause an exception, enter the keyword raise, followed by the name of the exception to be thrown. Exception names identify specific classes: Python exception handling is the object of those classes. When a raise statement is executed, Python creates an object for the specified exception class. The raise statement can also specify the initialization parameters for the exception object. Therefore, add a comma and a specified parameter (or a tuple consisting of parameters) after the name of the exception class ).

 


Python exception handling

Try to use either writable T or finally, and use writable t instead of finally.

How does python continue sequential execution after exception handling?

Statements placed in the try block may generate abnormal code. Capturing exceptions itself prevents possible errors in the program. The code that must be executed in sequence is not placed in the try block.
Try:
12/0
Failed t Exception, e
Print e
Finally:
Print "I'm pass"
Or add a finally block to the try foreign t statement. The finally statement is executed no matter whether an exception occurs or not.

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.