Hi. Le mer. 19 juin 2019 à 19:03, Ben Nguyen <bennguye...@gmail.com> a écrit : > > Hello, > > Inside AbstractMultipleLinearRegression.java in commons.math3.stat.regression > /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > > import org.apache.commons.math3.exception.DimensionMismatchException; > import org.apache.commons.math3.exception.InsufficientDataException; > import org.apache.commons.math3.exception.MathIllegalArgumentException; > import org.apache.commons.math3.exception.NoDataException; > import org.apache.commons.math3.exception.NullArgumentException; > import org.apache.commons.math3.exception.util.LocalizedFormats; > import org.apache.commons.math3.linear.NonSquareMatrixException; > > /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > > protected void validateSampleData(double[][] x, double[] y) throws > MathIllegalArgumentException { > if ((x == null) || (y == null)) { > throw new NullArgumentException(); > } > if (x.length != y.length) { > throw new DimensionMismatchException(y.length, x.length); > } > if (x.length == 0) { // Must be no y data either > throw new NoDataException(); > } > if (x[0].length + 1 > x.length) { > throw new MathIllegalArgumentException( > LocalizedFormats.NOT_ENOUGH_DATA_FOR_NUMBER_OF_PREDICTORS, > x.length, x[0].length); > } > } > /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > > I only have basic knowledge with exceptions, this is my first time hearing > about checked vs unchecked exceptions, currently trying to learn more about > it…. > So with these exceptions, which I assume are mostly (not all) checked?
No; all are unchecked (aka subclasses of "RuntimeException"). > How should I handle the porting of this specific method? Look at how it is done in e.g. "Commons Numbers". The current consensus is to only advertise (public API) standard JDK exceptions. Custom exception should be instantiated through a "factory". Regards, Gilles > > Thank you for your help, > -Ben > > > From: Alex Herbert > Sent: Wednesday, June 19, 2019 11:39 AM > To: Commons Developers List > Subject: Re: [GSoC][STATISTICS][Regression][Exception] How should I > handlehandling exceptions? > > On 19/06/2019 17:33, Ben Nguyen wrote: > > Hello, > > Regarding the use of exceptions for the regression module; should I simply > > try to port over all required exceptions straight from > > “apache.commons.math.exception” into it’s own exception package inside > > “regression.util.exception” perhaps customizing them to regression’s > > specific use cases as well….? Or will there be a full port of all > > exceptions for all modules to use…. though I do see one custom exception in > > “commons.distribution” so maybe not the latter? > > > > Thank you for your reply, > > Cheers, > > -Ben Nguyen > > > > > > Math used checked exceptions. > > I think the idea is to move to unchecked exceptions. In most cases this > should be for illegal arguments and this is why the distribution module > throws a special case of IllegalArgumentException. It is there to make > formatting of messages easy. > > What other types of exceptions are you expecting that cannot be > satisfied by? > > - IllegalStateException > > - ArithmeticException > > - Possibly others from the standard Java runtime exceptions > > Alex > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org