finallyworks.java
来自「think in java TIJ-3rd-edition-code.zip」· Java 代码 · 共 32 行
JAVA
32 行
//: c10:FinallyWorks.java
// The finally clause is always executed.
import com.bruceeckel.simpletest.*;
class ThreeException extends Exception {}
public class FinallyWorks {
static int count = 0;
public static void main(String[] args) {
SimpleTest monitor =
new SimpleTest("FinallyWorks");
while(true) {
try {
// Post-increment is zero first time:
if(count++ == 0)
throw new ThreeException();
System.out.println("No exception");
} catch(ThreeException e) {
System.err.println("ThreeException");
} finally {
System.err.println("In finally clause");
if(count == 2) break; // out of "while"
}
}
monitor.expect(new String[] {
"ThreeException",
"In finally clause",
"No exception",
"In finally clause"
});
}
} ///:~
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?