def exceptionhandler(exctype, value, traceback): if exctype == IndexError: parser.print_usage() else: sys.__excepthook__(exctype, value, traceback) # Set the system exception handler to the above definition.