SAX icon indicating copy to clipboard operation
SAX copied to clipboard

TSProcessor and SAXProcessor exception handling improvement

Open bernard01 opened this issue 6 years ago • 0 comments

Ideally, create and throw SAXRuntimeException.

In the following case, a checked exception is thrown on a condition similar to where typically java.lang.IndexOutOfBoundsException is thrown.

However IndexOutOfBoundsException extends RuntimeException.

There is little chance in the following case to meaningfully catch the checked exception and recover from it. Once it is thrown, it is game over because of a programming error.

SAXProcessor public char[] ts2string(double[] ts, int paaSize, double[] cuts, double nThreshold) throws SAXException {

throws it because it calls

TSProcessor public double[] paa(double[] ts, int paaSize) throws SAXException { if (len < paaSize) { throw new SAXException("PAA size can't be greater than the timeseries size."); }

What one ends up doing as a developer using this library is to ring fence the exception in a way like this:

final char[] ts2string; try { ts2string = sp.ts2string(windowSubseries, paaSize, na.getCuts(alphabetSize), normalizationThreshold); } catch (SAXException ex) { throw new RuntimeException(ex); }

which disrupts the work flow when writing software.

bernard01 avatar Aug 08 '17 07:08 bernard01