python - exception

category:

1. try/except #Catch exceptions and recover, slightly different from languages ​​such as java     


2. try/finally # Regardless of whether an exception occurs, the finally statement is executed, even if try and except contain return 

3.raise #Manually trigger an exception in the code


4.assert #Conditionally trigger an exception in the program, which can be regarded as a conditional raise  statement


5.with/as #implement environment manager

6. try/except/else #Execute except when an exception occurs, and execute else when it does not occur

try/except/else/finally can be used in combination, there can be multiple excepts, but there can only be one else and finally



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325938856&siteId=291194637