#The else block only gets executed if the try block terminates successfully i.e no exception was raised inside the block.
import math
try:
print("Hello, World!")
print(10/ 2)
print(math.sqrt(9))
except ValueError:
print("a valu error has occurred")
except IndexError:
print("IndexError has occurred")
else:
print("No Exception was raised.")
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter