File: try_except_continue.py

package info (click to toggle)
bandit 1.7.10-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,796 kB
  • sloc: python: 19,688; makefile: 23; sh: 14
file content (32 lines) | stat: -rw-r--r-- 360 bytes parent folder | download | duplicates (6)
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
# bad
for i in {0,1}:
    try:
        a = i
    except:
        continue


# bad
while keep_trying:
    try:
        a = 1
    except Exception:
        continue


# bad
for i in {0,2}:
    try:
        a = i
    except ZeroDivisionError:
        continue
    except:
        a = 2


# good
while keep_trying:
    try:
        a = 1
    except:
        a = 2