You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.5 KiB

4 years ago
  1. # coding: utf-8
  2. #
  3. # Copyright © 2010—2014 Andrey Mikhaylenko and contributors
  4. #
  5. # This file is part of Argh.
  6. #
  7. # Argh is free software under terms of the GNU Lesser
  8. # General Public License version 3 (LGPLv3) as published by the Free
  9. # Software Foundation. See the file README.rst for copying conditions.
  10. #
  11. """
  12. Exceptions
  13. ~~~~~~~~~~
  14. """
  15. class AssemblingError(Exception):
  16. """
  17. Raised if the parser could not be configured due to malformed
  18. or conflicting command declarations.
  19. """
  20. class DispatchingError(Exception):
  21. """
  22. Raised if the dispatching could not be completed due to misconfiguration
  23. which could not be determined on an earlier stage.
  24. """
  25. class CommandError(Exception):
  26. """
  27. Intended to be raised from within a command. The dispatcher wraps this
  28. exception by default and prints its message without traceback.
  29. Useful for print-and-exit tasks when you expect a failure and don't want
  30. to startle the ordinary user by the cryptic output.
  31. Consider the following example::
  32. def foo(args):
  33. try:
  34. ...
  35. except KeyError as e:
  36. print(u'Could not fetch item: {0}'.format(e))
  37. return
  38. It is exactly the same as::
  39. def bar(args):
  40. try:
  41. ...
  42. except KeyError as e:
  43. raise CommandError(u'Could not fetch item: {0}'.format(e))
  44. This exception can be safely used in both print-style and yield-style
  45. commands (see :doc:`tutorial`).
  46. """