Mar-11-2022, 08:16 AM
Hi,
Question without code, I'm looking for best practice.
Simplified: a program imports a class "sphere.py".
In sphere.py, 3 functions: Circonf(), Volume(), surface()
These calculations are called with the diameter as an argument.
ball = sphere(5)
v= ball.Volume() ....
Question:
What if sphere is called with a wrong argument (negative or string or zero...),
it generates an error in the class, but how will the main program know?
-
Should I simply put a try-except in the class and return some error code?
Or is there a more appropriate solution to this problem.
thx,
Paul
Question without code, I'm looking for best practice.
Simplified: a program imports a class "sphere.py".
In sphere.py, 3 functions: Circonf(), Volume(), surface()
These calculations are called with the diameter as an argument.
ball = sphere(5)
v= ball.Volume() ....
Question:
What if sphere is called with a wrong argument (negative or string or zero...),
it generates an error in the class, but how will the main program know?
-
Should I simply put a try-except in the class and return some error code?
Or is there a more appropriate solution to this problem.
thx,
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.