try{
   // some statements
}catch(Exception e){
   // 让finally块不执行
   // 请键入语句.
   //
}finally{
   System.out.println("finally");
}

解决方案 »

  1.   

    想法很好,finally不要执行......
      

  2.   

    首先你要明白   finally 的用法, 然后你才能决定 怎么能不让他执行
      

  3.   

    这是可能的
             try{
    System.out.println("try block");
    throw new Exception("测试");
    }catch(Exception e){
    System.out.println(e.toString());
    System.exit(0);
    }finally{
    System.out.println("1111");
    }
      

  4.   

    加个System.exit(0)不就行了吗
      

  5.   

    boolean caught = false;
    try{
      // do something
    }catch(Exception e){
       // error handler
       caught = true;
    }finally{
      if( ! caught ){
        // do something
      }
    }
      

  6.   

    让finally不执行,唔,除了System.exit(0)之外还可以拔电源。只要你手速够快。
      

  7.   

    LZ走火入魔了吧,别来搞java了。害人害己。
      

  8.   

    这可是退出的范围有点大呀,有没有只执行finally线程(进程)继续运行的方法??
      

  9.   

    加断点,调试到catch后,把电脑电源
      

  10.   

    finally,你伤不起啊,伤不起!!!!!!!!1
      

  11.   

    写了finally是要执行的,一般用来关闭流之类的。
    LZ不必纠缠于这个问题了,基本没有意义。。
      

  12.   

    这的确是个没有意义的问题。try{
      // some statements
    }catch(Exception e){
      // 让finally块不执行
      System.exit(0);
      //
    }finally{
      System.out.println("finally");
    }让其退出程序不就行了。
      

  13.   

    这样的题没什么意义吧,既然出现异常不想执行finally,为什么还要写上它呀
      

  14.   

    不要finally就不要加上嘛
    加上了还不要人家执行,
    真是六个指指头挠痒,多此一举
      

  15.   

    你如果想实现的话,只有这样了:
    try{
      // some statements
    }catch(Exception e){
     try{
     
     }catch(Exception e){
     
     }
    finally{
      System.out.println("finally");
    }
      

  16.   

    finally好像总是或被执行的,你要让一个总是要被执行的语句不执行?有个办法就像让一个人不吃饭一样,让他死掉就OK啦!
      

  17.   

    System.exit(0)  好东西啊
      

  18.   

    在守护线程中,finally 块的代码有可能不会执行。不知道 LZ 为何要这样做,finally 语句块本来就是要来写那些必须执行的代码。
      

  19.   

    哈哈,至于吗,就为了不让finally执行,还要切断电源,不执行不写不就可以吗
      

  20.   

    System.exit(0);
    或者
    while(true);
      

  21.   

    不让finally语句块执行,人为可以如楼上所说在catch语句块中加 system.exit(0),其实finally语句块一般是用于释放系统资源时写的,如:关闭数据流。可以独立使用。在多线程的程序中,finally语句块并不是一定会被执行。
      

  22.   

    呵呵,有意思 一个System.exit(0) 终止程序 一个while(true) 死循环
      

  23.   

    finally是始终执行的   用处 是为了防止 忘记关闭某些东西 做一些收尾处理的
      

  24.   

    纯粹无聊,不让执行你不写finally不就行了,何必折腾,想孔乙己知道茴香豆的几种写法,卖弄?
      

  25.   

    加断点,调试到catch后,把电脑电源
      

  26.   

           try{
              //
            }catch(Exception e){
                     System.exit(0);
            }finally{
                System.out.println("1111");
            }
      

  27.   

    如果 daemon 线程 或者 exit 可能不执行
      

  28.   

    无聊  不要他执行干嘛还写finally  真是吃饱撑着了
      

  29.   

    综上。总结出3个方法:1、System.exit(int n);2、设置断点,当程序执行到catch块的时候,退出虚拟机。3、楼主可以尝试重写一个虚拟机,保留finally的关键字,而且可以这么使用,但是它他妈的就是不执行,然后楼主可以定义一个finally1关键字,取代现有的finallywhile(boolean flag)啥的应该执行了吧。PS。 楼主很无聊,看到此回复很蛋疼,有木有!!
      

  30.   

    加catch中加入System.exit(0)可行,其他情况都会执行finally.
      

  31.   

    很高兴,好多人都知道了exit破坏程度。因此,很多做Swing的同学,应该知道JFrame.setDefaultCloseOperation的时候,不应该用EXIT_ON_CLOSE而是用DISPOSE_ON_CLOSE参数。
    话也不要说的太绝了:    try {
          throw new RuntimeException();
        } catch (Exception e) {
          for(;;); // 山无棱...
        } finally {
          System.out.println("finally");
        }
      

  32.   

        try {
          throw new RuntimeException();
        } catch (Exception e) {
          Thread.currentThread().suspend(); // Deprecated, but it does work.
        } finally {
          System.out.println("finally");
        }
      

  33.   

    第三击:    try {
          throw new RuntimeException();
        } catch (Exception e) {
          Object lock = new Object();
          synchronized (lock) {
            lock.wait();
          }
        } finally {
          System.out.println("finally");
        }
      

  34.   

    finally不执行,那你写她干嘛,try,catch语句后边的finally不是必须要写的,想不执行,不写不就完了
      

  35.   

    很好...  算是了解了exit如何破坏程序了...