summaryrefslogtreecommitdiff
path: root/tests/functional/exception_message.py
blob: da95c78f717a6cbab272b062b45f58f11c9131aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
Check accessing Exception.message
"""
# pylint: disable=import-error, no-absolute-import, broad-except

from unknown import ExtensionException
__revision__ = 0

class SubException(IndexError):
    """ empty """

_ = IndexError("test").message # [exception-message-attribute]
_ = ZeroDivisionError("error").message # [exception-message-attribute]
_ = ExtensionException("error").message
_ = SubException("error").message # [exception-message-attribute]

try:
    raise Exception('e')
except Exception as exception:
    _ = exception.message # [exception-message-attribute]
    del exception.message # [exception-message-attribute]
    exception.message += 'hello world' # [exception-message-attribute]
    exception.message = 'hello world'


class CompatException(Exception):
    """An exception which should work on py2 and py3."""

    def __init__(self, message=''):
        super(CompatException, self).__init__()
        self.message = message

    def __repr__(self):
        result = 'CompatException %s' % self.message
        return result.encode('utf-8')


try:
    raise CompatException('message here')
except CompatException as error:
    _ = error.message