📄 demonfinally.java
字号:
// 使用finally。
//演示finally的用法。
class DemonFinally {
// Through an exception out of the method.
static void methodA() {
try {
System.out.println("inside methodA");
throw new RuntimeException("demonstration");
}
finally {
System.out.println("methodA's finally");
}
}
// Return from within a try block.
static void methodB() {
try {
System.out.println("inside methodB");
return;
}
finally {
System.out.println("methodB's finally");
}
}
// Execute a try block normally.
static void methodC() {
try {
System.out.println("inside methodC");
}
finally {
System.out.println("methodC's finally");
}
}
public static void main(String args[]) {
try {
methodA();
}
catch (Exception e) {
System.out.println("Exception caught");
}
methodB();
methodC();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -