diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index ef2fd42783c877..fc1f6ca99a1991 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -2002,7 +2002,14 @@ Exiting methods .. method:: ArgumentParser.exit(status=0, message=None) This method terminates the program, exiting with the specified *status* - and, if given, it prints a *message* before that. + and, if given, it prints a *message* before that. The user can override + this method to handle these steps differently:: + + class ErrorCatchingArgumentParser(argparse.ArgumentParser): + def exit(self, status=0, message=None): + if status: + raise Exception(f'Exiting because of an error: {message}') + exit(status) .. method:: ArgumentParser.error(message)