summaryrefslogtreecommitdiff
path: root/tests/functional/t/try_except_raise.py
blob: 006a29bf91f0c7d7dc6b98dbb064aad1a023e023 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# pylint:disable=missing-docstring, unreachable, bad-except-order, bare-except, unnecessary-pass
# pylint: disable=undefined-variable, broad-except, raise-missing-from
try:
    int("9a")
except:  # [try-except-raise]
    raise

try:
    int("9a")
except:
    raise ValueError('Invalid integer')


try:
    int("9a")
except:  # [try-except-raise]
    raise
    print('caught exception')

try:
    int("9a")
except:
    print('caught exception')
    raise


class AAAException(Exception):
    """AAAException"""
    pass

class BBBException(AAAException):
    """BBBException"""
    pass

def ccc():
    """try-except-raise test function"""

    try:
        raise BBBException("asdf")
    except BBBException:
        raise
    except AAAException:
        raise BBBException("raised from AAAException")


def ddd():
    """try-except-raise test function"""

    try:
        raise BBBException("asdf")
    except AAAException:
        raise BBBException("raised from AAAException")
    except:  # [try-except-raise]
        raise

try:
    pass
except RuntimeError:
    raise
except:
    print("a failure")

try:
    pass
except:
    print("a failure")
except RuntimeError:  # [try-except-raise]
    raise

try:
    pass
except:  # [try-except-raise]
    raise
except RuntimeError:
    print("a failure")

try:
    pass
except (FileNotFoundError, PermissionError):
    raise
except OSError:
    print("a failure")

# also consider tuples for subsequent exception handler instead of just bare except handler
try:
    pass
except (FileNotFoundError, PermissionError):
    raise
except (OverflowError, OSError):
    print("a failure")

try:
    pass
except (FileNotFoundError, PermissionError):  # [try-except-raise]
    raise
except (OverflowError, ZeroDivisionError):
    print("a failure")

try:
    pass
except (FileNotFoundError, PermissionError):
    raise
except Exception:
    print("a failure")

try:
    pass
except (FileNotFoundError, PermissionError):
    raise
except (Exception,):
    print("a failure")