Skip to content

Commit 6a6044c

Browse files
committed
Add exception handling
1 parent c364676 commit 6a6044c

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

examples/example.py

+24-6
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,31 @@ def random_error():
6969
# Enter an infinite loop (with a 2 second sleep period), calling the "div_handled", "add", and "div_unhandled" methods,
7070
# in order to generate metrics.
7171
while True:
72-
ops.div_handled(2, 0)
72+
try:
73+
ops.div_handled(2, 0)
74+
except Exception:
75+
pass
76+
7377
ops.add(1, 2)
7478
ops.div_handled(2, 1)
75-
# Randomly call `div_unhandled` with a 50/50 chance of raising an error
76-
div_unhandled(2, random.randint(0, 1))
79+
80+
try:
81+
# Randomly call `div_unhandled` with a 50/50 chance of raising an error
82+
div_unhandled(2, random.randint(0, 1))
83+
except Exception:
84+
pass
85+
7786
ops.add(1, 2)
7887
time.sleep(2)
79-
# Call `div_unhandled` such that it raises an error
80-
div_unhandled(2, 0)
81-
random_error()
88+
89+
try:
90+
# Call `div_unhandled` such that it raises an error
91+
div_unhandled(2, 0)
92+
except Exception:
93+
pass
94+
95+
try:
96+
# Call random_error. It will randomly raise an error or return "ok"
97+
random_error()
98+
except Exception:
99+
pass

0 commit comments

Comments
 (0)