应为对流操作会抛出运行期错误,
在java中对于运行期的错误必须捕捉或者抛出

解决方案 »

  1.   

    class char1{
     public static void main(String args[]){
       String buffer;
    try{  
     BufferedReader my_in
             = new BufferedReader(new InputStreamReader(System.in));
       do{
          System.out.print("Enter a command:");
          System.out.flush();
          buffer = my_in.readLine();//提示这行出错,好像是readLine不能用。
       }while(!buffer.equals("exit"));
     }  
    }catch(Exception e){}//处理io异常,因为你对流进行了读写,就能出现读写错误,所以一定要处理io异常。

      

  2.   

    go to java's homepage you can find which method throw which exception ,then you can do with the exception in your code source
      

  3.   

    由于java追求的是无故障,健壮的代码,因此对一些可预知和不可预知的错误(如设备错误,算法缺陷等)要进行处理,有两种方法:
    一种是捕获:
    try{
     ... 
    }catch(xxException e){
      ...(出错处理)
    }
    一种是抛出
    xxx(xxx)//函数声明
    throws xxException{
     ...
    try{
      ...
    }catch(xxException e){
      throw e;
    }
    ....
    }
    一般io操作多需要捕获异常,下面的需要捕获IOException,
    BufferedReader my_in= new BufferedReader(new InputStreamReader(System.in));
      

  4.   

    只有在正确的抛出异常后才能够运行,这是由java的安全性决定的!,
      

  5.   

    Java的帮助文档上边,把每个类应该抛出的异常都有注明。因为考虑到鲁帮性,Java要求事先做异常的处理。所以你需要抛异常。