⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 finallyexam.java

📁 Java程序设计实用教程源代码 本书源代码按章分别放置在不同的文件夹中,所有程序均在JDK1.6环境下编译运行正常,除了第13章需要建立ODBC数据源之外,其他程序只要有Java运行环境即可直接运行
💻 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 + -