PageRenderTime 29ms CodeModel.GetById 24ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/argh/exceptions.py

https://bitbucket.org/neithere/argh/
Python | 39 lines | 15 code | 1 blank | 23 comment | 2 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"""
12Exceptions
13~~~~~~~~~~
14"""
15
16class CommandError(Exception):
17    """The only exception that is wrapped by the dispatcher. Useful for
18    print-and-exit tasks.
19
20    Consider the following example::
21
22        def foo(args):
23            try:
24                ...
25            except KeyError as e:
26                print(u'Could not fetch item: {0}'.format(e))
27                return
28
29    It is exactly the same as::
30
31        def bar(args):
32            try:
33                ...
34            except KeyError as e:
35                raise CommandError(u'Could not fetch item: {0}'.format(e))
36
37    This exception can be safely used in both print-style and yield-style
38    commands (see :doc:`tutorial`).
39    """