void main() { System.out.println("main begins"); try { a(); b(); } catch (Ex1 ex) { System.out.println("main caught Ex1"); } catch (Ex3 ex) { System.out.println("main caught Ex3"); } finally { System.out.println("main finally"); } System.out.println("main completes"); } void a() { System.out.println("a begins"); try { if (condForEx1) { b(); } else { throw new Ex1(); } } catch (Ex2 ex) { System.out.println("a caught Ex2"); } System.out.println("a completes"); } void b() { System.out.println("b begins"); try { if (condForEx2) throw new Ex2(); if (condForEx3) throw new Ex3(); } catch (Ex3 ex) { System.out.println("b caught ex3"); } finally { System.out.println("b finally"); } System.out.println("b completes"); }
For each part below determine the complete output that would be output if the code above was run with the values of the condForEx variables as specified below. Assume the exception classes Ex1, Ex2, and Ex3 each extend RuntimeException. If an exception is passed out of main, show the output of the runtime environment as "Program terminated due to Exception ExN ", where N is the particular exception number.
Consider the following secret generic method:
public static <E> boolean secret(Listnode<E> chain1, Listnode<E> chain2) { while (chain1 != null && chain2 != null) { if (chain1.getData().equals(chain2.getData())) { chain1 = chain1.getNext(); chain2 = chain2.getNext(); } else return false; } if (chain1 == null && chain2 == null) return true; return false; }