[SciPy-dev] How to handle exceptional cases in algorithms ? Exception vs Warning
Mon Jun 4 06:23:57 CDT 2007
I have a general question regarding the implementation of algorithm
in python. When something unusual, but possible (that is it is a
limitation of the algorithm, not a bug), is there a global policy which
is better than another one: emitting a warning vs exception.
For example, I recently reworked a bit the internal of
scipy.cluster, which implements Vector Quantization and kmean algorithm.
For those not familiar with those algorithms, the goal of kmeans is to
separate a dataset into k clusters according to a criteria generally
based on euclidian distance. Sometimes, it may happens during
computation that one of the cluster has no data attached to it, which
means that the algorithm won't returns k clusters at the end. Emitting a
warning means that the computation can continue anyway, but those cases
cannot be caught programmatically. On the contrary, raising an exception
can be caught, but needs to be handled, and may break running code.
Is there really one choice better then the other, or is it a matter
of taste ?
More information about the Scipy-dev