In writing a Python program, you should always include some form of error checking. Doing so allows the computer to fail softly instead of giving the user an ugly error message. It also means that if one thing goes wrong the entire program does not grind to a halt.
To provide this safety net, use 'try...except'. 'try' tells the computer to attempt to do something. 'except' tells it what to do on failure. The syntax goes like this:
try:
a = open("sample.txt", "r")
except IOError, error:
print error
