withfinally.java

来自「think in java TIJ-3rd-edition-code.zip」· Java 代码 · 共 24 行

JAVA
24
字号
//: c10:WithFinally.java
// Finally Guarantees cleanup.
import com.bruceeckel.simpletest.*;

public class WithFinally {
  static Switch sw = new Switch();
  public static void main(String[] args) {
    SimpleTest monitor =
      new SimpleTest("WithFinally");
    try {
      sw.on();
      // Code that can throw exceptions...
      OnOffSwitch.f();
    } catch(OnOffException1 e) {
      System.err.println("OnOffException1");
    } catch(OnOffException2 e) {
      System.err.println("OnOffException2");
    } finally {
      sw.off();
    }
    monitor.expect(new String[] {
    });
  }
} ///:~

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?