पायथन में अपवादों को संभालने का सबसे आसान तरीका "कोशिश-छोड़कर" ब्लॉक का उपयोग करना है।
उदाहरण
try:
fob = open("test.txt", "r")
fob.write("This is my test file for exception handling!!")
except IOError:
print "Error: can\'t find the file or read data"
else:
print "Write operation is performed successfully on the file"
fob.close() आउटपुट
Error: can't find the file or read data