两个程序,分别为ServerTimout.java,别一个为Servertim.java但编译通不过,说是少“;”,可我也没发现什么地方少啊!
public class ServerTimout extends Exception{
   private String reason;
   private int port;
   public ServerTimout(String reason,int port){
      this.reason=reason;
      this.port=port;
      //if(port==80)throw new ("没法连接端口:",80)
   }
   public String getreason(){
      return reason;
   }
   public int getport(){
      return port;
   }
}
-------------------
public class Servertim{
    public void timout(int port) throws ServerTimout{
        if(port==80)throw new ServerTimout("没法连接端口:",80)
    }
    public static void main(String args[]){
       Servertim a=new Servertim();
       try{
           a.timout(80);
       }catch(Servertim b){
           System.out.println(b.getreason());
           
       }
    }
}
请网友帮看看!

解决方案 »

  1.   

    我发现了:
    if(port==80)throw new ServerTimout("没法连接端口:",80)少了";"
      

  2.   

    }catch(Servertim b){ 改为}catch(ServerTimout b){ 
    命名有点不行!!!!
      

  3.   

    if(port==80)throw new ServerTimout("没法连接端口:",80)少了";"
    并且将catch(Servertim b) 改为 catch(ServerTimout e)
      

  4.   

    强烈建议LZ去看看Java Tutorial,还有时间的话可以看看Java语言规范
      

  5.   

    说实话,我刚学JAVA,没几天,看一本叫《JAVA面向对象编程(孙卫琴)》的书,有看不明白的地方,才上来问的,刚看到异常处理这个地方,还没有接处什么真正的程序呢!如果楼上的有更好的书集,可以介绍给我!