Exception Handling (3)
I. Exception BasicsTry/retry T: capture and recover exceptions in the code, match errors in wait t, and manually commit the code defined in T, and then continue to execute the program (when an exception occurs, after
Mistakes happen almost every day in a programmer's life. In the past period, errors were either fatal to the program (and possibly the machine), or they produced a whole bunch of meaningless output that could not be identified by other computers or
In all programs, you will encounter exceptions, some of which are generated when code is written, and may cause the program to fail to run directly during the early stages. This class of exceptions, when writing code, the program can directly
Exception handling 1. Exceptions and Errors Part1: Errors are unavoidable in the program, and errors are divided into two 1) syntax errors (this error, the parser can not get through the syntax detection, must be corrected before the program
1. BasicTry/except/else: "Else is optional" Catch the exception in the code and recover, match except inside the error, and execute the code defined in except, and then continue executing the program (after the exception is caught by except after
Exceptions and ErrorsOne: Syntax error (this error, the syntax of the Python interpreter cannot be detected, must be corrected before the program executes)# Syntax error demonstration one if# syntax error demonstration two defPass# syntax error demo
What ' s the anomalyThere is an exception in the Python program, which is the bug. If the exception program error, the code after the exception will not continue to execute, this is a normal program is not allowed to appear, but in some programs to
Introduction to five exception handling mechanisms in python, and Exception Handling in python
Since learning programming a few years ago, I have been afraid and exclusive to program exception handling. This is because you do not know. In this
Python file read/write and Exception Code example,
I. Reading data from a file
#!/usr/bin/env pythonwith open('pi') as file_object: contents = file_object.read() print(contents) ===================================3.1415926 5212533 2324255
1. Read
Python has powerful exception handling capabilities and can accurately report error information to users. In Python, exceptions are also objects that can be operated on. All exceptions are members of the base class Exception. All exceptions are
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.