Skip to content

Commit 3123215

Browse files
committed
Add divide by zero handling in sample and test classes
1 parent 97c47ed commit 3123215

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

python/sample.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ def meanage(filename):
1919

2020
return str(mean_age)
2121

22+
def dividezero(x):
23+
return x / 0
24+
2225
# print(meanage("/home/irisowner/dev/data/titanic.csv"))

requirements.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
numpy==1.23.4
2-
pandas==1.5.0
3-
dataclasses-json==0.5.7
4-
sqlalchemy-iris==0.10.5
5-
flask==2.3.3
6-
requests==2.31.0
1+
numpy
2+
pandas
3+
dataclasses-json
4+
sqlalchemy-iris
5+
flask
6+
requests

src/dc/python/test.cls

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,30 @@ ClassMethod TitanicMeanAge() As %Status
3535
Return sc
3636
}
3737

38+
ClassMethod DivideByZero() As %Status
39+
{
40+
Set sc = $$$OK
41+
set tt=##class(%SYS.Python).Import("sample")
42+
try {
43+
write "divide by zero="_tt.dividezero(1)
44+
#dim ex as %Exception.PythonException
45+
} catch ex {
46+
do ex.Log()
47+
write "Caught exception: ", ex.DisplayString(), !
48+
}
49+
Return sc
50+
}
51+
52+
ClassMethod DivideByZeroPython() [ Language = python ]
53+
{
54+
import sample
55+
import iris
56+
try:
57+
print("divide by zero=" + str(sample.dividezero(1)))
58+
except ZeroDivisionError as e:
59+
errobj=iris.cls("%Exception.General")._New(str(e),42)
60+
a=errobj.Log()
61+
print("Caught exception: " + str(e))
62+
}
63+
3864
}

0 commit comments

Comments
 (0)