static void throwMethod() throws IllegalAccessException{
  ......
}

解决方案 »

  1.   

    public class ThrowsDemo { 
    static void throwMethod() throws IllegalAccessException { 
    System.out.println("Inside throwMethod."); 
    throw new IllegalAccessException("demo"); 

    public static void main(String args[]) { 
    try { 
    throwMethod(); 

    catch (IllegalAccessException e) { 
    System.out.println("Caught " + e); 


    }如果不在throwMethod()跑出异常,如何在main()中catch这个异常