For example for the following method signature:
def genClusters(n_clusters, n_nodes, cluster_distribution):
n_clusters should be an integer of more than 1.
n_nodes should be an integer of more than
cluster_distribution should be a float between 0 and 1.
Should I use a series of
if then raise exception statements to handle the argument parameter bounds?
def genClusters(n_clusters, n_nodes, cluster_distribution): if (cluster_distribution < 0 or cluster_distribution > 1): raise ValueError("cluster distribution must be between 0 and 1") if n_clusters < 1: raise ValueError("n_clusters must be at least 1") if n_nodes <= n_clusters: raise ValueError("n_nodes must be at least n_clusters")
The second question is whether I should include these exception statements in every method that also calls this one.
def myFoo(foo, bar, bang): clusters = genClusters(foo, bar, bang)
In this scenario, if foo, bar, or bang don't fit previously defined parameter bounds, an exception will be thrown when
genClusters is called. So should I also be throwning exceptions at the start of