下面列出了怎么用java.lang.ArithmeticException的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 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");
}
/**
* 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);
}
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));
}
/**
* 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;
}