可以考虑用循环控制.
不知是不是这个意思。
int flag=1;
while(flag==1){
               flag=0;
               try{
                    .......//需要捕捉的语句
               }
               catch(Exception e){
                    flag=1;       
               }
 }

解决方案 »

  1.   

    要回到违例发生的地方,上面的代码做不到吧!因为不知违例到底在那里发生,如果在try中有三个可能发生不同违例的地方,这么解决啊!
    我想是做不到!
      

  2.   

    to needle:那么我每次catch一个语句可以吗?
      

  3.   

    to:lmy2000
    可以可以,佩服,佩服版主!
      

  4.   

    斑竹的这个办法好奇怪啊。
    这样的话已经违背了try/catch的原意了。
      

  5.   

    谢谢luodi的提醒。
    倒不是一定要说出对错,其实我也从没有这么做过也没有碰到过这样的问题,只是看到这个问题,提出想法而已。具体能否实行也在实验,我觉得既然有这样的想法就可以做这样的实验。另外,希望hiseh()能说出这样做的原因。应该不会是凭空想象出来的吧。
    我想有时违背常理的问题也还是蛮有启发性的。
      

  6.   

    目前的jdk应该不行的。
    以后可能会有,赫赫。
      

  7.   

    55555 ... hiseh, 你解决了, 可是 ... 现在我又想要了 :(
      

  8.   

    看看这个测试,是否对你们有帮助
    class MyException  extends Exception {
      public MyException(String msg){
       super(msg);
      }
    }
    public class ExceptionTest
    {  public ExceptionTest()
      {
      }  public void f() throws Exception{
       try{
          throw new MyException("MyException in f()");
        }finally{
          System.out.println("Finally in f()");
        }
      }  public void g() throws Exception{
       try{
        f();
       }catch(Exception e){
        e.printStackTrace();
        System.out.println("Cath Exception in g()");
        throw new MyException("MyException in g()");
       }  }
      public static void main(String[] args)
      {
        ExceptionTest t = new ExceptionTest();
        try{
          t.g();
        }catch(Exception e){
         e.printStackTrace();
        }
      }}
    输出:
    Finally in f()
    untitled1.MyException: MyException in f()
            at untitled1.ExceptionTest.f(ExceptionTest.java:18)
            at untitled1.ExceptionTest.g(ExceptionTest.java:26)
            at untitled1.ExceptionTest.main(ExceptionTest.java:38)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.borland.jbuilder.util.BootStrap.invokeMain(Unknown Source)
            at com.borland.jbuilder.util.BootStrap.main(Unknown Source)
    Cath Exception in g()
    untitled1.MyException: MyException in g()
            at untitled1.ExceptionTest.g(ExceptionTest.java:30)
            at untitled1.ExceptionTest.main(ExceptionTest.java:38)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.borland.jbuilder.util.BootStrap.invokeMain(Unknown Source)
            at com.borland.jbuilder.util.BootStrap.main(Unknown Source)