public class TryThrowCatchFinally2 { public static void main(String[] args) { try { otherMethod(); } catch (DivideByZero d) { System.err.println(d.getMessage()); } catch (OverFlow ov) { System.err.println(ov.getMessage()); } finally { System.out.println("All done."); } } private static void otherMethod() throws DivideByZero, OverFlow { final double dividend = Double.MAX_VALUE; final double divisor = 2 * Math.random(); if (divisor == 0.0) { throw new DivideByZero(); } if (divisor < 1.0) { throw new OverFlow(); } System.out.println(dividend/divisor); } } class DivideByZero extends Exception { public DivideByZero() { super("can't divide by zero"); } } class OverFlow extends Exception { public OverFlow() { super("quotient would overflow"); } }