// A hyper-simple example of exception throw and try/catch public class TheObject { int data = 2; public void askIt(int value) throws Exception { if (value == data) throw new Exception("ok"); else throw new Exception("NOT OK"); } public static void main(String[] args) { TheObject oracle = new TheObject(); for (int i=0; i<10; i++) { try { oracle.askIt(i); System.out.println("here"); } catch (Exception e){ System.out.println("caught exception." + e + " i= " + i); } } } }