The following part of the code has trouble static void throwMethod() { System.out.println("Inside throwMethod."); throw new IllegalAccessException("demo"); } throwMethod actually throws exception. So, either the IllegalAccessException exception (or its superclass) should be cought or the method has to declare that it throws IllegalAccessException exception (or its super class). try changing the method as static void throwMethod() throws IllegalAccessException { System.out.println("Inside throwMethod."); throw new IllegalAccessException("demo"); }