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

📄 trycatchexam.java

📁 Java程序设计实用教程源代码 本书源代码按章分别放置在不同的文件夹中,所有程序均在JDK1.6环境下编译运行正常,除了第13章需要建立ODBC数据源之外,其他程序只要有Java运行环境即可直接运行
💻 JAVA
字号:
public class trycatchExam {          
  public static void main(String args[]) { // main method
    try {
      method1(); // call method1
      System.out.println("method1执行完毕");
    }

    catch (Exception exception) { //捕获method1抛出的异常
      System.err.println(exception.getMessage());
      exception.printStackTrace();
    }
    System.out.println("程序结束");
  }
  public static void method1() throws Exception { 
    method2();// call method2; throw exceptions
  }
  public static void method2() throws Exception { // 用throw语句抛出异常
    throw new Exception("Exception thrown in method2");
  }
}

⌨️ 快捷键说明

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