📄 finallyexam.java
字号:
public class finallyExam {
private static int iStart = 0;
private static int iEnd = 50;
public static void main(String args[]) {
testFinally();
}
public static void throwException() throws Exception {
try {
System.out.println("Method throwException");
throw new Exception(); // generate exception
}
catch (Exception exception) {
System.err.println("Exception handled in method throwException");
throw exception; // rethrow for further processing
}
finally {
System.err.println("Finally executed in throwException");
}
}
public static void testFinally() {
try {
while(true){
if(iStart == iEnd)
throwException();
iStart ++;
iEnd --;
}
}
catch (Exception exception) {
System.out.println("iStart = iEnd, throw Exception");
System.err.println(exception.toString());
}
finally {
System.out.println("In finally: 重新初始化 iStart and iEnd");
iStart = 0;
iEnd = 50;
}
System.out.println("End of method testFinally");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -