package com.abelski.samples; public class MyExceptionHandlingDemo { public static void main(String args[]) { int val = 123; try { aa(val); } catch (MyException e) { e.printStackTrace(); } finally { System.out.println("finally always works"); } val = -123; try { aa(val); } catch (MyException e) { e.printStackTrace(); } finally { System.out.println("finally always works"); } } static void aa(int num) throws MyException { System.out.println("aa start"); bb(num); System.out.println("aa end"); } static void bb(int val) throws MyException { System.out.println("bb start"); cc(val); System.out.println("bb end"); } static void cc(int number) throws MyException { System.out.println("cc start"); if (number < 0) { throw new MyException("negative number"); } else { System.out.println(number + " log is " + Math.log(number)); } System.out.println("cc end"); } }