java.lang.ArithmeticException Java Examples

The following examples show how to use java.lang.ArithmeticException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: constructor.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs the test using the specified harness.
 *
 * @param harness  the test harness (<code>null</code> not permitted).
 */
public void test(TestHarness harness)
{
    ArithmeticException object1 = new ArithmeticException();
    harness.check(object1 != null);
    harness.check(object1.toString(), "java.lang.ArithmeticException");

    ArithmeticException object2 = new ArithmeticException("nothing happens");
    harness.check(object2 != null);
    harness.check(object2.toString(), "java.lang.ArithmeticException: nothing happens");

    ArithmeticException object3 = new ArithmeticException(null);
    harness.check(object3 != null);
    harness.check(object3.toString(), "java.lang.ArithmeticException");

}
 
Example #2
Source File: TryCatch.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Runs the test using the specified harness.
 *
 * @param harness  the test harness (<code>null</code> not permitted).
 */
public void test(TestHarness harness)
{
    // flag that is set when exception is caught
    boolean caught = false;
    try {
        throw new ArithmeticException("ArithmeticException");
    }
    catch (ArithmeticException e) {
        // correct exception was caught
        caught = true;
    }
    harness.check(caught);
}
 
Example #3
Source File: SpecialMathFunction.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static double atanh(double x) throws ArithmeticException {
  if ((x > 1.0) || (x < -1.0)) {
    throw new ArithmeticException("range exception");
  }
  return 0.5 * Math.log((1.0 + x) / (1.0 - x));
}
 
Example #4
Source File: SpecialMathFunction.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Get the log base 2 of a number
 * 
 * @param x a double value
 * @return The log<sub>2</sub> of x
 * @throws ArithmeticException if (x < 0)
 */
public static double log2(double x) throws ArithmeticException {
  if (x <= 0.0)
    throw new ArithmeticException("range exception");
  return Math.log(x) / log2;
}