小弟暑假在家自学JAVA,遇到问题,请大家帮忙解决下;
//定义WhcaException异常类
class WhcaException extends Exception{    public WhcaException(){
    }
 
    public WhcaException(String s){
        super(s);
    }
}
public class ExceptionUse {    public static void main(String args[]) {
        try{
             execute();
        }
        catch(WhcaException e){
              System.out.println(e.getMessage());
        }
    }    static void execute() throws WhcaException{
             try{
                 throw new Exception();
             }
             //捕获Exception类
             catch(Exception e){
                  //捕获后,不进行处理,而是再抛出WhcaException异常类
                   throw new WhcaException("something is wrong:"+e.getMessage());
             }
      }
}书上说得不是很详细,哪位大哥,大姐姐能帮忙详细的说一下它的执行过程吗,谢谢了。

解决方案 »

  1.   


    //定义WhcaException异常类 
    //Exception是所有异常类的超类
    class WhcaException extends Exception{ //定义构造方法
        public WhcaException(){ 
        }     public WhcaException(String s){ 
            super(s); 
        } 
    } //测试类
    public class ExceptionUse {     public static void main(String args[]) { 
            try{ 
               //执行测试方法,抛出WhcaException 类异常
                execute(); 
            } 
            catch(WhcaException e){ 
                 //捕捉WhcaException 类异常,打印异常信息
                  System.out.println(e.getMessage()); 
            } 
        } //定义测试方法
        static void execute() throws WhcaException{ 
                try{ 
                    //抛出一个异常
                    throw new Exception(); 
                } 
                //捕获Exception类 
                catch(Exception e){ 
                      //捕获后,不进行处理,而是再抛出WhcaException异常类 
                      throw new WhcaException("something is wrong:"+e.getMessage()); 
                } 
          } 
      

  2.   

    try{ 
               //执行测试方法,抛出WhcaException 类异常
                execute(); 
            } 
            catch(WhcaException e){ 
                 //捕捉WhcaException 类异常,打印异常信息
                  System.out.println(e.getMessage()); 
            } 
      

  3.   

    static void execute() throws WhcaException
    这里是声明了 execute() 方法是一个受检查的方法 
    throws 的意思是该方法有可能抛出一个异常  实现该方法时并不一定要抛出异常的。