Generic error handling example.
#!/usr/bin/python ############################################################################## # file: common_error.py # # 'msparser' toolkit example code # ############################################################################## # COPYRIGHT NOTICE # # Copyright 1998-2010 Matrix Science Limited All Rights Reserved. # # # ############################################################################## # $Source: parser/examples/test_python/common_error.py $ # # $Author: villek@matrixscience.com $ # # $Date: 2018-07-30 16:23:53 +0100 $ # # $Revision: 1b450440f9c97e1e41d0fc6016a27d68951d4532 | MSPARSER_REL_2_8_1-0-gea32989045 $ # # $NoKeywords:: $ # ############################################################################## 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'. """
Copyright © 2022 Matrix Science Ltd. All Rights Reserved. Generated on Thu Mar 31 2022 01:12:29 |