diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2020-05-29 17:43:02 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-29 17:43:02 -0400 |
commit | 8d9405a1fcc2169aa039172a8e2891b839a59e6c (patch) | |
tree | 53d94a01e7421f8ffba8c8df3ef640c16413b008 /cmd2/exceptions.py | |
parent | d4653e6fccf0bc15d04075110769c11befb22819 (diff) | |
parent | 9b91116ec523f1bb27ae8c353a2a7a1dc7975888 (diff) | |
download | cmd2-git-8d9405a1fcc2169aa039172a8e2891b839a59e6c.tar.gz |
Merge pull request #937 from python-cmd2/exceptions
Exception handling
Diffstat (limited to 'cmd2/exceptions.py')
-rw-r--r-- | cmd2/exceptions.py | 27 |
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 |