# -*- coding: utf-8 -*- # Let's try making a custom exception. # Usage: python 21.py number # It will throw an error if the number is non hexadecimal import sys, string class NonHexException(Exception): pass def printHexNumber(hexString): hexDigits = string.hexdigits for c in theString: if not c in hexDigits: raise NonHexException("Not a hexadecimal number") print hexString theString = sys.argv[1] try: printHexNumber(theString) except NonHexException: print "Error: this is not a hexadecimal number"