class a extends Exception
{
a()
{
}
a(String s)
{
super(s);
}
}class a11
{
static void f(int b) throws a
{
if (b>10)
{
throw(new a("出错啦"));
}
System.out.println("a1*a1:="+(b*b));
}
}
class Q
{
public static void main(String[] args)
{
try
{
//a1 a1= new a1();
a11.f(50);
a11.f(5);
}
catch (a e)
{
System.out.println(e.toString());
}
}
}
当我第一次输入的数据错误(f(50))的时候 后面的数据(f(5))也被跳过了 这种情况怎么处理呢?谢谢

解决方案 »

  1.   

    记的下次发代码的时候,格式化一下,不然看着好费眼。
    class a extends Exception 

    a() 
    {  } 
    a(String s) 

    super(s); 

    } class a11 

    static void f(int b) throws a 

    if (b>10) 

    throw(new a("出错啦")); 

    System.out.println("a1*a1:="+(b*b)); 




    class Q

    public static void main(String[] args) 

    try 

    //a1 a1= new a1(); 
    a11.f(50); 


    catch (a e) 

    System.out.println(e.toString()); 
    } finally { ///放到finally里就可以了
    try
    {
    a11.f(5); 
    }
    catch (Exception e)
    {

    }
    }

      

  2.   

    那你得分别try啊try 

    //a1 a1= new a1(); 
    a11.f(50);  //异常,就被catch了,下面的当然不执行了,你可以分别catch
    a11.f(5); 
    }try 

    //a1 a1= new a1(); 
    a11.f(50); 

    catch (a e) 

    System.out.println(e.toString()); 
    }
    try 

    //a1 a1= new a1(); 
    a11.f(5); 

    catch (a e) 

    System.out.println(e.toString()); 
    }
      

  3.   

    又迟了一步try  
    {  
    //a1 a1= new a1();  
    a11.f(50);  
    }  
    catch (a e)  
    {  
    System.out.println(e.toString());  

    try  
    {  
    //a1 a1= new a1();  
    a11.f(5);  
    }  
    catch (a e)  
    {  
    System.out.println(e.toString());  
    }
      

  4.   

    两个还好说 要是多个呢?
    比如输入的是一组数据 发现其中有不符合的就跑出错误
    总不能一个一个地try吧...
      

  5.   

    要想达到你的那功能的话,你这个方法f()内部实现错,你应该在内部catch之后不throw而,按照正常来处理!
    这样才能达到你的预期目的!
      

  6.   

    LSD 能说的仔细一点么?没太明白
      

  7.   

    就是一个一个try啊,有异常就跳,你放在catch前怎么执行得到。
    一般多个都是数组或者能由变量控制的,所以只要放循环语句就行了。
    比如你这题,你要多个,你就放数组啊。
    由键盘不断输入也行啊。
      

  8.   

    这样,要多少个往数组里加。class a extends Exception 

        a() {} 
        
        a(String s) 
        { 
          super(s); 
        } 

    class a11

        static void f(int b) throws a 
        { 
            if (b>10) 
            { 
                throw(new a("出错啦")); 
            } 
            System.out.println("a1*a1:="+(b*b)); 
        } 

            
            
    class Q

        public static void main(String[] args) 
        { 
         int[] i ={50,5,1,2,11,4};
         for(int j=0;j<i.length;j++)
         {
        
            try 
            { 
                
                a11.f(i[j]); 
                
            } 
            catch (a e) 
            { 
                System.out.println(e.toString()); 
            } 
            }
        } 

      

  9.   

    把a11.f(50)与a11.f(5)分别放到两个try块中就可以了