Thursday, August 4, 2011

Test Exception


package com.evs.objava33.class9;

public class TestException {

private static int[] intArray = { 1, 2, 3, 4, 5, 6 };

public static void main(String[] args) {
try {
// Catchable Code
// System.out.println(3 / 0);
System.out.println(getValue(3, 0.0));
System.out.println(getArrayValue(7));
} catch (Exception e) {
System.out.println("Exception occur: Please contact ");
e.printStackTrace();
} finally {
// Clean up
}
}

public static int getValue(final Integer i, final Double j)
throws Exception {
return (int) (i / j);
}

private static int getArrayValue(int i) throws MyExceptionClass {
try {
return intArray[i];
} catch (Exception e) {
e.printStackTrace();
throw new MyExceptionClass(e);
}
}

}

No comments:

Post a Comment