Wrapped entire code block in try to catch exceptions

Added a few different exceptions that are likely to happen
when trying to use this tool. It then offers useful feedback
and quits.
This commit is contained in:
A.M. Rowsell 2021-03-30 08:25:07 -04:00
commit 487f6ffb46
Signed by: amr
GPG key ID: 0B6E2D8375CF79A9

View file

@ -23,7 +23,8 @@ static unsigned char {0}_bits [] =
outputData = b''
with open(filename + ".MSP", 'rb') as f:
try:
with open(filename + ".MSP", 'rb') as f:
versionString = f.read(4)
if versionString == b'\x4c\x69\x6e\x53':
version = 2
@ -92,3 +93,12 @@ with open(filename + ".MSP", 'rb') as f:
f.write(outputString)
print("Done!")
sys.exit(0)
except FileNotFoundError:
print("{0}.MSP does not exist! Quitting...".format(filename))
sys.exit(255)
except PermissionError:
print("Unable to open {0}.MSP -- insufficient permissions! Quitting...".format(filename))
sys.exit(255)
except Exception:
print("Something went wrong! Quitting...")
sys.exit(255)