abnormal
error signal
Once the program fails, if there is no corresponding processing mechanism in the program,
Then the error will generate an exception thrown, and the program will be terminated.
The three parts of an exception:
1. Abnormal tracking information
2. Types of exceptions
3. Unusual values
There are many kinds of exceptions, we give two examples
#Exception classification # Syntax exception (this exception is corrected before program execution) try: x except NameError: print( ' Syntax exception ' ) # Logical exception try: l=[] l[1] except IndexError: print( ' Logical problem ' )
Exception (universal exception)
# Universal exception
try:
x=0
y
print('====>')
l=[]
l[1]
dic={'a':0}
dic['b']
except Exception as e:
print(' Universal exception 123',e)
# The result is universal exception 123 name 'y' is not defined
try:
x=0
print('====>')
l=[]
l[1]
dic={'a':0 }
dic['b']
except Exception as e:
print('Universal exception 123',e)
#Result====>
# Universal exception 123 list index out of range
try...else...(else cannot be used alone, it must be used in conjunction with except)
Executes without any exception in the detected code block
#try...else... try: print( ' I have no exception ' ) except Exception: print( ' Universal exception ' ) else : print( ' Seagrass, seagrass, dance in seaweed waves ' )
try...finally..
will be executed whether or not an exception occurs
#try..finally try: x = 0 print('====>') l = [] l[1] dic = { ' a ' : 0 } dic['b'] except Exception: print( ' Universal exception 123 ' ) finally : print( ' Big brother, don't kill me ' )
Actively trigger exceptions
raise
# raise NameError class Peopel: def __init__(self,name): if not isinstance(name,str): raise TimeoutError( ' %s must be of type str ' % name) self.name=name p=Peopel(123)
Affirmation
# Affirmation print('part1........') stus = [ ' I 'm ' , ' Alex ' , ' wxx ' _ _ _ # stus=[] if len(stus) <= 0: raise TypeError assert len(stus) > 0 print('part2.........') print('part2.........') print('part2.........') print('part2.........') print('part2.........') print('part2.........')
custom exception
# Custom exception class RegisterError(BaseException): def __init__(self,msg,user): self.msg=msg self.user=user def __str__(self): return '<%s:%s>' %(self.user,self.msg) raise RegisterError( ' Registration failed ' , ' teacher ' )
network programming
1.C/s, B/s architecture
client<---->server
browser<---->server
Learning socket programming is to write a client software and server software
Then realize the communication between the server and the client based on the network
2. What is a network?
1. Physical connection medium
2. Internet Protocol
internet protocol is
osi seven-layer protocol
Physical layer function: mainly based on electrical characteristics to send high and low voltage (electrical signals), high voltage corresponds to digital 1, low voltage corresponds to digital 0
Data Link Layer: Ethernet
- A group of electrical signals that make up a packet, called a 'frame'
- Each data frame is divided into two parts: header head and data data
- mac address: each network card is burned with a unique mac address in the world when it leaves the factory
network layer ip address
transport layer port
user-level software
I can locate any unique software in the world through mac+lp+port