> > [...] > > > In fact, such an exception would be raised if the program stumbles > > > upon to vectors x and y such as x'Ay differs from y'Ax. So, the > > > existing NonSymmetricMatrixException would be a particular case of a > > > more general (BasicNonSymetricMatrixException ?), with x = ei and y > > > = ej. In this case, the meaning of the tolerance would be the same > > > for both exceptions. > > > >So, messy as it is, I agree with > > > >Gilles that the best solution is to have both forms of witnessed > > > >exceptions derive from a common base. So, for example, > > > >NonSymmetricMatrixException has something like > > > >MatrixSymmetryException and SymmetricOperationException as subclasses. > > > > > > > So maybe instead of creating two new exceptions, maybe one would be > enough? > > > BasicNonSymmetricMatrixException > > > +--NonSymmetricMatrixException > > > > > > Imagine for a moment we go for this solution. Then it would be nice > > > (for debugging purposes), to be able to retrieve x and y from > > > BasicNonSymmetricMatrixException. These vectors would however > > > presumably be huge, so it's out of the question to print them in the > > > error message. They should just be available, which requires to > > > create new getters. > > > > That those getters will be defined in "BasicNonSymmetricMatrixException" > > but won't be initialized in "NonSymmetricMatrixException", is another > > reason for having two distinct exceptions deriving from a common base > class. > > I don't agree there: these getters are still meaningful in > "NonSymmetricMatrixException". For the sake of the argument, let's call them > getFirstOffendingVector and getSecondOffendingVector. If > NonSymmetricMatrixException is raised by > |a[i,j] - a[j,i]| > tol, > then > - getFirstOffendingVector could return (construct) ei = [0, ..., 1, ..., 0] > (i-th component is the only non-zero value) > - similarly, getSecondOffendingVector could return (construct) ej. > On top of that, NonSymmetricMatrixException would still implement getRow(), > getColumn(), while the base class BasicSymmetricMatrixException would only > implement getFirstOffendingVector and getSecondOffendingVector. > > In this case, getRow() and getColumn() make the more general methods > getFirstOffendingVector and getSecondOffendingVector pretty much pointless, > but *not meaningless*.
The question is thus: Is it OK to provide pointless methods? I also wonder whether it is reasonable to _generate_ state variables just so that the accessors can return them. Usually, when a exception is constructed, it is _passed_ data that provide the context of the failure (i.e. the vectors or the indices that show the problem). In this case, if the test (that triggered the exception) was not performed using vectors, it looks quite strange to be able to retrieve vectors... Gilles --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org