Does finally always get called?

Possible Duplicate:
In Java, does return trump finally?

What does this function return?

public int wasExceptionThrown() {
   try {
     if(1==1)
        throw new RuntimeException();
     return 1;
   } catch(Exception e) {
     return 2;
   } finally {
     return 3;
   }
   return 0;
}

If you call System.exit(0); then finally blocks are not called as the thread is shutdown immediately. In all other cases finally is called when the block exits (assuming it does)


Finally called before return.

The only time finally won't be called is if you call System.exit() or if the JVM crashes first.

链接地址: http://www.djcxy.com/p/73706.html

上一篇: 在java中尝试/ catch块返回与finally子句

下一篇: 终于总是被叫?