2022-06-03 | Web | #Words: 119
try...except...finally
statement is used to handle errors and return information. The format is as follows:
try:
code
except:
code
finally:
code
try
indicates attempting to execute this code. If unsuccessful, the except
section will be returned. However, regardless of the attempted execution result, the content of finally
will be returned.
For example:
#!/usr/bin/python3
try:
x>3
except:
print('error')
finally:
print('finally')
Return:
$ ./try.py
error
finally