1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /** 18 * Test math exceptions 19 */ 20 public class Main { math_014()21 public static void math_014() { 22 int expectedThrows = 2; 23 int i; 24 long j; 25 float f = 0.0f; 26 double d = 0.0; 27 28 try { i = 10 / 0; } 29 catch (ArithmeticException ae) { 30 expectedThrows--; 31 } 32 33 try { j = 10L / 0L; } 34 catch (ArithmeticException ae) { 35 expectedThrows--; 36 } 37 38 /* 39 * Floating point divide by zero doesn't throw an exception -- the 40 * result is just NaN. 41 */ 42 try { f = 10.0f / f; } 43 catch (ArithmeticException ae) { 44 expectedThrows--; 45 } 46 47 try { d = 10.0 / d; } 48 catch (ArithmeticException ae) { 49 expectedThrows--; 50 } 51 52 if (expectedThrows != 0) 53 System.out.println("HEY: expected throws is " + expectedThrows); 54 else 55 System.out.println("testMath3 success"); 56 } main(String args[])57 public static void main(String args[]) { 58 math_014(); 59 } 60 } 61