/argh/exceptions.py

https://bitbucket.org/neithere/argh/ · Python · 39 lines · 15 code · 1 blank · 23 comment · 0 complexity · d0a5b20458c4755f74fb663bfc629218 MD5 · raw file

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (c) 2010—2013 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 for copying conditions.
  10. #
  11. """
  12. Exceptions
  13. ~~~~~~~~~~
  14. """
  15. class CommandError(Exception):
  16. """The only exception that is wrapped by the dispatcher. Useful for
  17. print-and-exit tasks.
  18. Consider the following example::
  19. def foo(args):
  20. try:
  21. ...
  22. except KeyError as e:
  23. print(u'Could not fetch item: {0}'.format(e))
  24. return
  25. It is exactly the same as::
  26. def bar(args):
  27. try:
  28. ...
  29. except KeyError as e:
  30. raise CommandError(u'Could not fetch item: {0}'.format(e))
  31. This exception can be safely used in both print-style and yield-style
  32. commands (see :doc:`tutorial`).
  33. """