PythonTry Else
Try Else
You can use theelse
keyword to define a block of code to be executed if no errors were raised:
Example
In this example, thetry
block does not generate any error:
try:
print("Hello")
except:
print("Something went wrong")
else:
print("Nothing went wrong")
Try it Yourself »print("Hello")
except:
print("Something went wrong")
else:
print("Nothing went wrong")