public class add {
    public static void main(String[] args) {
        add a=new add();
        a.saveabc(1);//提示错误,我该如何修正这个错误
    }  public int saveabc(int a) throws Exception
  {
     
      try{
      System.out.print("d");
          
      }catch(Exception e){
          System.out.print("dd");
      }
      return a;
  }  
  
}

解决方案 »

  1.   

    哦,你调用的方法有返回值啊,但你并没有进行任何操作,a.saveabc(1) 返回一个数字,相当于a;没有表达式啊!
      

  2.   

    没有捕获异常呗既然你的方法引发了异常,在调用需要捕获或者继续throws Exception
    public int saveabc(int a) throws Exceptionpublic static void main(String[] args) {
            add a=new add();
    try
    {
            a.saveabc(1);//提示错误,我该如何修正这个错误
    }
    catch (Exception ex)//需要捕获该方法抛出的异常
    {
    }
        }
      

  3.   

    你的方法既然是这样声明的,就不用再在这个方法中捕获异常了
    public int saveabc(int a) throws Exception如果你在这个方法捕获了异常也就不用再throws向上抛异常了
    你这样的写法没有任何意义可这样:
    public int saveabc(int a) throws Exception
      {
         
          try{
          System.out.print("d");
              
          }catch(Exception e){
              throw new Exception(ex.toString());
          }
          return a;
      }  也可这样:
    public int saveabc(int a)  {
         
          try{
          System.out.print("d");
              
          }catch(Exception e){
              System.out.print("dd");
          }
          return a;
      }
      

  4.   

    public static void main(String[] args) throws Exception{
            add a=new add();
            a.saveabc(1);//提示错误,我该如何修正这个错误
        }
      

  5.   

    注意这里:public static void main(String[] args) throws Exception{
                                                    ~~~~~~~~~~~~~~~~
      

  6.   

    public class add {
        public static void main(String[] args) {
            add a=new add();
            int c=a.saveabc(1);//提示错误,我该如何修正这个错误
        }  public int saveabc(int a) throws Exception
      {
         int b=a;
          try{
          System.out.print("d");
              
          }catch(Exception e){
              System.out.print("dd");
          }
          return b;
      }  
      
    }
      

  7.   

    import java.io.*;
    public class add {
        public static void main(String[] args) throws Exception
    {
            add a=new add();
            int b=a.saveabc(1);//提示错误,我该如何修正这个错误
        }  public int saveabc(int a)
      {
         
          try{
          System.out.print("d");
              
          }catch(Exception e){
              System.out.print("dd");
          }
          return a;
      }  
    }
    这样就好了  
      

  8.   

    要么 把跑出异常的去掉,要末就try catch