Replace errors by unchecked exceptions

Bug: 20667245

Also makes the exception classes local to CR, consistent with 21st
century programming style.

Change-Id: Iea7956715d8942fa87c6cd68fb6a9ca11ea73b89
diff --git a/src/com/hp/creals/AbortedError.java b/src/com/hp/creals/AbortedError.java
deleted file mode 100644
index 1468805..0000000
--- a/src/com/hp/creals/AbortedError.java
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright (c) 1999, Silicon Graphics, Inc. -- ALL RIGHTS RESERVED
-//
-// Permission is granted free of charge to copy, modify, use and distribute
-// this software  provided you include the entirety of this notice in all
-// copies made.
-//
-// THIS SOFTWARE IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTY OF ANY
-// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
-// WARRANTIES THAT THE SUBJECT SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT
-// FOR A PARTICULAR PURPOSE OR NON-INFRINGING.   SGI ASSUMES NO RISK AS TO THE
-// QUALITY AND PERFORMANCE OF THE SOFTWARE.   SHOULD THE SOFTWARE PROVE
-// DEFECTIVE IN ANY RESPECT, SGI ASSUMES NO COST OR LIABILITY FOR ANY
-// SERVICING, REPAIR OR CORRECTION.  THIS DISCLAIMER OF WARRANTY CONSTITUTES
-// AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY SUBJECT SOFTWARE IS
-// AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
-//
-// UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING,
-// WITHOUT LIMITATION, NEGLIGENCE OR STRICT LIABILITY), CONTRACT, OR
-// OTHERWISE, SHALL SGI BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL,
-// INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER WITH RESPECT TO THE
-// SOFTWARE INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK
-// STOPPAGE, LOSS OF DATA, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL
-// OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SGI SHALL HAVE BEEN INFORMED OF
-// THE POSSIBILITY OF SUCH DAMAGES.  THIS LIMITATION OF LIABILITY SHALL NOT
-// APPLY TO LIABILITY RESULTING FROM SGI's NEGLIGENCE TO THE EXTENT APPLICABLE
-// LAW PROHIBITS SUCH LIMITATION.  SOME JURISDICTIONS DO NOT ALLOW THE
-// EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THAT
-// EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
-//
-// These license terms shall be governed by and construed in accordance with
-// the laws of the United States and the State of California as applied to
-// agreements entered into and to be performed entirely within California
-// between California residents.  Any litigation relating to these license
-// terms shall be subject to the exclusive jurisdiction of the Federal Courts
-// of the Northern District of California (or, absent subject matter
-// jurisdiction in such courts, the courts of the State of California), with
-// venue lying exclusively in Santa Clara County, California.
-
-package com.hp.creals;
-
-/**
-* Indicates a constructive real operation was interrupted.
-* Most constructive real operations may throw such an error.
-* This is an error, since Number methods may not raise such
-* exceptions.
-*/
-public class AbortedError extends Error {
-    public AbortedError() { super(); }
-    public AbortedError(String s) { super(s); }
-}
diff --git a/src/com/hp/creals/CR.java b/src/com/hp/creals/CR.java
index 3812f90..dba2597 100644
--- a/src/com/hp/creals/CR.java
+++ b/src/com/hp/creals/CR.java
@@ -151,11 +151,11 @@
 * provides the same functionality, but adds the caching necessary to obtain
 * reasonable performance.
 * <P>
-* Any operation may throw <TT>com.hp.creals.AbortedError</tt> if the thread in
+* Any operation may throw <TT>com.hp.creals.AbortedException</tt> if the thread in
 * which it is executing is interrupted.  (<TT>InterruptedException</tt> cannot
 * be used for this purpose, since CR inherits from <TT>Number</tt>.)
 * <P>
-* Any operation may also throw <TT>com.hp.creals.PrecisionOverflowError</tt>
+* Any operation may also throw <TT>com.hp.creals.PrecisionOverflowException</tt>
 * If the precision request generated during any subcalculation overflows
 * a 28-bit integer.  (This should be extremely unlikely, except as an
 * outcome of a division by zero, or other erroneous computation.)
@@ -168,6 +168,29 @@
     // We could do without the latter, but that would
     // be atrociously slow.
 
+/**
+ * Indicates a constructive real operation was interrupted.
+ * Most constructive real operations may throw such an exception.
+ * This is unchecked, since Number methods may not raise checked
+ * exceptions.
+*/
+public static class AbortedException extends RuntimeException {
+    public AbortedException() { super(); }
+    public AbortedException(String s) { super(s); }
+}
+
+/**
+ * Indicates that the number of bits of precision requested by
+ * a computation on constructive reals required more than 28 bits,
+ * and was thus in danger of overflowing an int.
+ * This is likely to be a symptom of a diverging computation,
+ * <I>e.g.</i> division by zero.
+*/
+public static class PrecisionOverflowException extends RuntimeException {
+    public PrecisionOverflowException() { super(); }
+    public PrecisionOverflowException(String s) { super(s); }
+}
+
     // First some frequently used constants, so we don't have to
     // recompute these all over the place.
       static final BigInteger big0 = BigInteger.ZERO;
@@ -183,7 +206,7 @@
 
 /**
 * Setting this to true requests that  all computations be aborted by
-* throwing AbortedError.  Must be rest to false before any further
+* throwing AbortedException.  Must be rest to false before any further
 * computation.  Ideally Thread.interrupt() should be used instead, but
 * that doesn't appear to be consistently supported by browser VMs.
 */
@@ -229,7 +252,7 @@
         // that should be as cheap as possible.
         int high_shifted = n >> 29;
         if (0 != (high ^ high_shifted)) {
-            throw new PrecisionOverflowError();
+            throw new PrecisionOverflowException();
         }
       }
 
@@ -376,7 +399,7 @@
             int msd = msd(prec);
             if (msd != Integer.MIN_VALUE) return msd;
             check_prec(prec);
-            if (Thread.interrupted() || please_stop) throw new AbortedError();
+            if (Thread.interrupted() || please_stop) throw new AbortedException();
         }
         return msd(n);
       }
@@ -614,7 +637,7 @@
         long long_msd_prec = (long)(log2_radix * (double)m);
         if (long_msd_prec > (long)Integer.MAX_VALUE
             || long_msd_prec < (long)Integer.MIN_VALUE)
-            throw new PrecisionOverflowError();
+            throw new PrecisionOverflowException();
         int msd_prec = (int)long_msd_prec;
         check_prec(msd_prec);
         int msd = iter_msd(msd_prec - 2);
@@ -1196,7 +1219,7 @@
         BigInteger max_trunc_error =
                 big1.shiftLeft(p - 4 - calc_precision);
         while (current_term.abs().compareTo(max_trunc_error) >= 0) {
-          if (Thread.interrupted() || please_stop) throw new AbortedError();
+          if (Thread.interrupted() || please_stop) throw new AbortedException();
           n += 1;
           /* current_term = current_term * op / n */
           current_term = scale(current_term.multiply(op_appr), op_prec);
@@ -1239,7 +1262,7 @@
         current_term = big1.shiftLeft(-calc_precision);
         BigInteger current_sum = current_term;
         while (current_term.abs().compareTo(max_trunc_error) >= 0) {
-          if (Thread.interrupted() || please_stop) throw new AbortedError();
+          if (Thread.interrupted() || please_stop) throw new AbortedException();
           n += 2;
           /* current_term = - current_term * op * op / n * (n - 1)   */
           current_term = scale(current_term.multiply(op_appr), op_prec);
@@ -1286,7 +1309,7 @@
         BigInteger max_trunc_error =
                 big1.shiftLeft(p - 2 - calc_precision);
         while (current_term.abs().compareTo(max_trunc_error) >= 0) {
-          if (Thread.interrupted() || please_stop) throw new AbortedError();
+          if (Thread.interrupted() || please_stop) throw new AbortedException();
           n += 2;
           current_power = current_power.divide(big_op_squared);
           current_sign = -current_sign;
@@ -1331,7 +1354,7 @@
         BigInteger max_trunc_error =
                 big1.shiftLeft(p - 4 - calc_precision);
         while (current_term.abs().compareTo(max_trunc_error) >= 0) {
-          if (Thread.interrupted() || please_stop) throw new AbortedError();
+          if (Thread.interrupted() || please_stop) throw new AbortedException();
           n += 1;
           current_sign = -current_sign;
           x_nth = scale(x_nth.multiply(op_appr), op_prec);
@@ -1396,7 +1419,7 @@
                                     // before division by the exponent.
                                     // Accurate to 3 ulp at calc_precision.
         while (current_term.abs().compareTo(max_last_term) >= 0) {
-          if (Thread.interrupted() || please_stop) throw new AbortedError();
+          if (Thread.interrupted() || please_stop) throw new AbortedException();
           exp += 2;
           // current_factor = current_factor * op * op * (exp-1) * (exp-2) /
           // (exp-1) * (exp-1), with the two exp-1 factors cancelling,
diff --git a/src/com/hp/creals/PrecisionOverflowError.java b/src/com/hp/creals/PrecisionOverflowError.java
deleted file mode 100644
index f62e7f4..0000000
--- a/src/com/hp/creals/PrecisionOverflowError.java
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright (c) 1999, Silicon Graphics, Inc. -- ALL RIGHTS RESERVED
-//
-// Permission is granted free of charge to copy, modify, use and distribute
-// this software  provided you include the entirety of this notice in all
-// copies made.
-//
-// THIS SOFTWARE IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTY OF ANY
-// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
-// WARRANTIES THAT THE SUBJECT SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT
-// FOR A PARTICULAR PURPOSE OR NON-INFRINGING.   SGI ASSUMES NO RISK AS TO THE
-// QUALITY AND PERFORMANCE OF THE SOFTWARE.   SHOULD THE SOFTWARE PROVE
-// DEFECTIVE IN ANY RESPECT, SGI ASSUMES NO COST OR LIABILITY FOR ANY
-// SERVICING, REPAIR OR CORRECTION.  THIS DISCLAIMER OF WARRANTY CONSTITUTES
-// AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY SUBJECT SOFTWARE IS
-// AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
-//
-// UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING,
-// WITHOUT LIMITATION, NEGLIGENCE OR STRICT LIABILITY), CONTRACT, OR
-// OTHERWISE, SHALL SGI BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL,
-// INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER WITH RESPECT TO THE
-// SOFTWARE INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK
-// STOPPAGE, LOSS OF DATA, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL
-// OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SGI SHALL HAVE BEEN INFORMED OF
-// THE POSSIBILITY OF SUCH DAMAGES.  THIS LIMITATION OF LIABILITY SHALL NOT
-// APPLY TO LIABILITY RESULTING FROM SGI's NEGLIGENCE TO THE EXTENT APPLICABLE
-// LAW PROHIBITS SUCH LIMITATION.  SOME JURISDICTIONS DO NOT ALLOW THE
-// EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THAT
-// EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
-//
-// These license terms shall be governed by and construed in accordance with
-// the laws of the United States and the State of California as applied to
-// agreements entered into and to be performed entirely within California
-// between California residents.  Any litigation relating to these license
-// terms shall be subject to the exclusive jurisdiction of the Federal Courts
-// of the Northern District of California (or, absent subject matter
-// jurisdiction in such courts, the courts of the State of California), with
-// venue lying exclusively in Santa Clara County, California.
-
-package com.hp.creals;
-
-/**
-* Indicates that the number of bits of precision requested by
-* a computation on constructive reals required more than 28 bits,
-* and was thus in danger of overflowing an int.
-* This is likely to be a symptom of a diverging computation,
-* <I>e.g.</i> division by zero.
-*/
-public class PrecisionOverflowError extends Error {
-    public PrecisionOverflowError() { super(); }
-    public PrecisionOverflowError(String s) { super(s); }
-}
-
diff --git a/src/com/hp/creals/UnaryCRFunction.java b/src/com/hp/creals/UnaryCRFunction.java
index 60bf9c9..6f8ef5d 100644
--- a/src/com/hp/creals/UnaryCRFunction.java
+++ b/src/com/hp/creals/UnaryCRFunction.java
@@ -431,7 +431,7 @@
             BigInteger difference = h.subtract(l);
             for(int i = 0;; ++i) {
                 if (Thread.interrupted() || please_stop)
-                    throw new AbortedError();
+                    throw new AbortedException();
                 trace("***Iteration: " + i);
                 trace("Arg prec = " + working_arg_prec
                       + " eval prec = " + working_eval_prec
@@ -653,7 +653,7 @@
                 return scale(appr_left_deriv, -extra_prec);
             } else {
                 if (Thread.interrupted() || please_stop)
-                    throw new AbortedError();
+                    throw new AbortedException();
                 deriv2_msd[0] =
                         eval_prec + deriv_difference.bitLength() + 4/*slop*/;
                 deriv2_msd[0] -= log_delta;