public static string GetMessage(MatrixOperationType matrixType) { switch (matrixType) { case MatrixOperationType.Addition: return("The two matrices could not be added because their dimensions were unequal."); case MatrixOperationType.Determinant: return("The determinant of a non-square matrix does not exist."); case MatrixOperationType.Division: return("A matrix cannot be divided by the zero element of its field."); case MatrixOperationType.Eigenvalue: return("Only square matrices have eigenvalues."); case MatrixOperationType.Eigenvector: return("Only square matrices have eigenvectors."); case MatrixOperationType.Inverse: return("Only square matrices with non-zero determinant have an inverse."); case MatrixOperationType.Multiplication: return("The two matrices could not be multiplied, the width of the first" + "should be equal to the height of the second."); case MatrixOperationType.Trace: return("The trace of a matrix exists only if the matrix is square."); case MatrixOperationType.Unit: return("Only square matrices can be a unit matrix."); } throw new ArgumentException("The given MatrixOperationType was " + "not a valid object."); }
public IncompatibleOperationException(MatrixOperationType type, string message) : base(message) { MatrixType = type; }
public IncompatibleOperationException(MatrixOperationType type) : base(GetMessage(type)) { MatrixType = type; }