summaryrefslogtreecommitdiff
path: root/cmd2/exceptions.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2020-06-01 00:45:15 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2020-06-01 00:45:15 -0400
commiteb41d46c1f6c6281e57e8b864fa4500d3509ed55 (patch)
tree0b515e33f78b45f7eefa9dd2dcbe5bcc14baa0ec /cmd2/exceptions.py
parent19a142782bc1272af870cd893fd25fc7f19c9940 (diff)
parent8d9405a1fcc2169aa039172a8e2891b839a59e6c (diff)
downloadcmd2-git-eb41d46c1f6c6281e57e8b864fa4500d3509ed55.tar.gz
Merge branch 'master' into hint_bug
Diffstat (limited to 'cmd2/exceptions.py')
-rw-r--r--cmd2/exceptions.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/cmd2/exceptions.py b/cmd2/exceptions.py
index 635192e1..8a7fd81f 100644
--- a/cmd2/exceptions.py
+++ b/cmd2/exceptions.py
@@ -1,16 +1,33 @@
# coding=utf-8
-"""Custom exceptions for cmd2. These are NOT part of the public API and are intended for internal use only."""
+"""Custom exceptions for cmd2"""
-class Cmd2ArgparseError(Exception):
+############################################################################################################
+# The following exceptions are part of the public API
+############################################################################################################
+
+class SkipPostcommandHooks(Exception):
"""
- Custom exception class for when a command has an error parsing its arguments.
- This can be raised by argparse decorators or the command functions themselves.
- The main use of this exception is to tell cmd2 not to run Postcommand hooks.
+ Custom exception class for when a command has a failure bad enough to skip post command
+ hooks, but not bad enough to print the exception to the user.
"""
pass
+class Cmd2ArgparseError(SkipPostcommandHooks):
+ """
+ A ``SkipPostcommandHooks`` exception for when a command fails to parse its arguments.
+ Normally argparse raises a SystemExit exception in these cases. To avoid stopping the command
+ loop, catch the SystemExit and raise this instead. If you still need to run post command hooks
+ after parsing fails, just return instead of raising an exception.
+ """
+ pass
+
+
+############################################################################################################
+# The following exceptions are NOT part of the public API and are intended for internal use only.
+############################################################################################################
+
class Cmd2ShlexError(Exception):
"""Raised when shlex fails to parse a command line string in StatementParser"""
pass