The try
block lets you test a block of code for errors.
The except
block lets you handle the error.
The finally
block lets you execute code, regardless of the result of the try- and except blocks.
You can define as many exception blocks as you want, e.g. if you want to execute a special block of code for a special kind of error:
ExamplePrint one message if the try block raises a NameError
and another for other errors:
try:
print(x)
except NameError:
print("Variable x is not defined")
except:
print("Something else went wrong")
Track your progress - it's free!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4