We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4210ad5 commit b1a2abdCopy full SHA for b1a2abd
Doc/library/argparse.rst
@@ -2029,7 +2029,14 @@ Exiting methods
2029
.. method:: ArgumentParser.exit(status=0, message=None)
2030
2031
This method terminates the program, exiting with the specified *status*
2032
- and, if given, it prints a *message* before that.
+ and, if given, it prints a *message* before that. The user can override
2033
+ this method to handle these steps differently::
2034
+
2035
+ class ErrorCatchingArgumentParser(argparse.ArgumentParser):
2036
+ def exit(self, status=0, message=None):
2037
+ if status:
2038
+ raise Exception(f'Exiting because of an error: {message}')
2039
+ exit(status)
2040
2041
.. method:: ArgumentParser.error(message)
2042
0 commit comments