Java examples for Object Oriented Design:Exception
Two basic types of exceptions in Java are checked exceptions and unchecked exceptions:
public class Main { public static void uncheckedException() { int a = 5;/* www . j a v a 2 s . c om*/ int b = 0; int c = a / b; // not catching } public static void uncheckedException2() { int a = 5; int b = 0; try { int c = a / b; // but you try it anyway } catch (ArithmeticException e) { System.out.println("Oops, you can't divide by zero."); } } }