python learning - Exception

# NameError variable name can not be found abnormal
# IndexError subscript bounds exception
# KeyError dictionary form, there is no abnormality key
# AssertionError assertion exception.
# AttributeError property exception. Properties of the object does not exist.
# SyntaxError Syntax error
# IndentationError abnormal indentation

Abnormal # FileExistsError file, when you want to create a directory or a file
# PermissionError permission exception. No operating authority.

mydict = {"key":"value"}
#print(mydict["hello"])


# Further to deal with exceptions. Appeared abnormal, I would also like doing doing!
"" "A pattern:
the try:
XXXX # think this piece of code would be abnormal
except:
After catching exceptions, I think I do things written log # # shot.
The raise # thrown.
A finally:
With or without abnormal the code will eventually be executed. # finishing touches
"" "


"" "Mode two:
try:
XXXX # think this piece of code would be abnormal
except:
After catching exceptions, I think I do things written log # # shot.
The raise # thrown.
The else:
no exceptions, then try in the code, proceed.
[a finally:]
"" "

# Http connection

 

FS = None #
# the try:
# FS = Open ( "moviessss.txt", encoding = "UTF-. 8")
# Print (fs.read ())
# the except:
# Print ( "file read failed")
# The raise # thrown
# a finally:
# Print ( "I will certainly work performed !!")
# IF FS iS not None:
# fs.Close ()


#print ( "I will execute you do it right !!!")

str_a = input ( "Please enter a number:")

The try the except the else #
the try:
B = int (str_a)
the except:
Print ( "data input defective, non-numeric !!!")
the else:
Print (22 is B +) # abnormality without the try
the finally:
Print ( " heheheheh ")

Guess you like

Origin www.cnblogs.com/qsmyjz/p/11261232.html