We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a0d4aac commit 6dc3e61Copy full SHA for 6dc3e61
Doc/library/argparse.rst
@@ -2001,7 +2001,14 @@ Exiting methods
2001
.. method:: ArgumentParser.exit(status=0, message=None)
2002
2003
This method terminates the program, exiting with the specified *status*
2004
- and, if given, it prints a *message* before that.
+ and, if given, it prints a *message* before that. The user can override
2005
+ this method to handle these steps differently::
2006
+
2007
+ class ErrorCatchingArgumentParser(argparse.ArgumentParser):
2008
+ def exit(self, status=0, message=None):
2009
+ if status:
2010
+ raise Exception(f'Exiting because of an error: {message}')
2011
+ exit(status)
2012
2013
.. method:: ArgumentParser.error(message)
2014
0 commit comments