File size: 779 Bytes
c574d3a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import java.io.IOException;
public class ExceptionHandling {
private static String printEvenOrOdd(int digit) throws IOException {
// try {
// System.out.println(5 / 0);
// } catch (Exception e) {
// System.out.println("Exception handled in printEvenOrOdd");
// }
// System.out.println(5 / 0);
throw new IOException();
// return (digit % 2 == 0) ? "Even" : "Odd";
}
public static void main(String[] args) {
System.out.println("Before Exception Occurs");
try {
System.out.println(printEvenOrOdd(5));
} catch (Exception e) {
System.out.println("Exception handled in main");
}
System.out.println("After the exception has occurred");
}
}
|