Generic error handling example.
import msparser
import sys
def main() :
file = msparser.ms_datfile()
if len(sys.argv) > 1 :
file.setFileName(sys.argv[1])
else :
file.setFileName("wrong_name.txt")
file.read_file()
if file.isValid() :
print("The file has been read and parsed successfully. Congratulations!")
else :
checkErrorHandler(file)
def checkErrorHandler(obj) :
print("Last error description ")
print("=========================================")
print("Error: %s" % obj.getLastErrorString())
print("=========================================")
print("Testing the error handling... ")
print("=========================================")
err = obj.getErrorHandler()
for i in range(1 + err.getNumberOfErrors()) :
print("Error number: %d (%d times): %s" % (
err.getErrorNumber(i),
err.getErrorRepeats(i) + 1,
err.getErrorString(i)
))
obj.clearAllErrors()
if __name__ == "__main__":
sys.exit(main())
""" Running the program with no arguments, for example with
python common_error.py
will give the output:
Last error description
=========================================
Error: Cannot find Mascot configuration file 'wrong_name.txt'.
=========================================
Testing the error handling...
=========================================
Error number: 0 (1 times):
Error number: 1537 (1 times): Cannot find Mascot configuration file 'wrong_name.txt'.
"""