Python exceptions and exception handling

Python exceptions and exception handling:

When the program is running, the error that occurs is called an exception

Example:

  0 cannot be used as a divisor: ZeroDivisionError

  Variable is undefined: NameError

  Adding different types: TypeError

Exception handling:

'' ' 
try: 
    execute code 
except: 
    code 

executed when an exception occurs Try statement: 
    if an exception occurs, jump to the except statement 

    If there is no exception, then run the try statement and continue the statement after the exception 
    
' ''

 

Guess you like

Origin www.cnblogs.com/hany-postq473111315/p/12303328.html